获取桌面文件路径[已解决]
本帖最后由 wants 于 2014-11-1 09:20 编辑想做个右键将文件上传的网盘,下面的代码对打开的文件夹好像能取得路径,但是桌面上的路径取不到,请教一下大家,要怎么修改才能取到桌面路径。$hExplorer = WinGetHandle( "" )
If Not $hExplorer Then Exit
; Shell object
$oShell = ObjCreate( "Shell.Application" )
; Find window
For $oWindow In $oShell.Windows()
If $oWindow.HWND() = $hExplorer Then ExitLoop
Next
; Selected items
For $oItem In $oWindow.Document.SelectedItems()
ConsoleWrite( $oItem.Path() & @CRLF )
Next
MsgBox(0,0,@DesktopDir) 我要选中文件的路径 好源码,值得学习 本帖最后由 wants 于 2014-10-31 14:43 编辑
自己整了一下,貌似达到了自己想要的效果,需将文件添加到右键的发送到才有效果,在XP和WIN7下试了都可以,可多选发送。#Region ;**** 参数创建于 ACNWrapper_GUI ****
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
; Windows Explorer on XP, Vista, 7, 8
;$hExplorer = WinGetHandle( "" )
$hExplorer = WinGetHandle( "" )
GetFocusedFullPath()
Func opendir()
$oShell = ObjCreate( "Shell.Application" )
; Find window
For $oWindow In $oShell.Windows()
If $oWindow.HWND() = $hExplorer Then ExitLoop
Next
For $oItem In $oWindow.Document.SelectedItems()
;ConsoleWrite( $oItem.Path() & @CRLF )
If $oItem.Path()<>"" Then
MsgBox(0, "1",$oItem.Path())
;FileWrite ( "www.ini", $oItem.Path())
EndIf
Next
; Selected items
EndFunc
Func GetFocusedFullPath()
$ListViewHWnd = ControlGetHandle("", "", "SysListView32")
$ItemSelectedId = ControlListView("", "", $ListViewHWnd, "GetSelected",1)
$dz1 = StringSplit($ItemSelectedId, "|", 1)
If $dz1 >=1 Then
For $t = 1 To $dz1
$ItemText = ControlListView("", "", $ListViewHWnd, "GetText", $dz1[$t])
$Path = ControlGetText("", "", "Edit1")
If $ItemText<>"" And $path<>"" Then
opendir()
ExitLoop
ElseIf $ItemText<>"" Then
If StringInStr(StringRight($ItemText, 4),".")=0Then
$kzm=".*"
Else
$kzm=""
EndIf
$search = FileFindFirstFile( @DesktopDir &"\"&$ItemText&$kzm)
$file = FileFindNextFile($search)
;MsgBox(0, "2", @DesktopDir &"\"& $file)
FileWrite ( "www.ini", @DesktopDir &"\"& $file&@CRLF)
Else
opendir()
EndIf
Next
EndIf
EndFunc ;==>GetFocusedFullPath
。
页:
[1]