从资源管理器中,获取被选择的文件的路径(及文件夹)的API
2017-09-05 17:02
453 查看
从下面的URL中,获得了这个Library.
Get paths of selected items in an explorer window
转载自:http://wjason.iteye.com/blog/1955712
Get paths of selected items in an explorer window
/* http://www.autohotkey.com/board/topic/60985-get-paths-of-selected-items-in-an-explorer-window/ Library for getting info from a specific explorer window (if window handle not specified, the currently active window will be used). Requires AHK_L or similar. Works with the desktop. Does not currently work with save dialogs and such. Explorer_GetSelected(hwnd="") - paths of target window's selected items Explorer_GetAll(hwnd="") - paths of all items in the target window's folder Explorer_GetPath(hwnd="") - path of target window's folder example: F1:: path := Explorer_GetPath() all := Explorer_GetAll() sel := Explorer_GetSelected() MsgBox % path MsgBox % all MsgBox % sel return Joshua A. Kinnison 2011-04-27, 16:12 */ Explorer_GetPath(hwnd="") { if !(window := Explorer_GetWindow(hwnd)) return ErrorLevel := "ERROR" if (window="desktop") return A_Desktop path := window.LocationURL path := RegExReplace(path, "ftp://.*@","ftp://") StringReplace, path, path, file:/// StringReplace, path, path, /, \, All ; thanks to polyethene Loop If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex) StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All Else Break return path } Explorer_GetAll(hwnd="") { return Explorer_Get(hwnd) } Explorer_GetSelected(hwnd="") { return Explorer_Get(hwnd,true) } Explorer_GetWindow(hwnd="") { ; thanks to jethrow for some pointers here WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A") WinGetClass class, ahk_id %hwnd% if (process!="explorer.exe") return if (class ~= "(Cabinet|Explore)WClass") { for window in ComObjCreate("Shell.Application").Windows if (window.hwnd==hwnd) return window } else if (class ~= "Progman|WorkerW") return "desktop" ; desktop found } Explorer_Get(hwnd="",selection=false) { if !(window := Explorer_GetWindow(hwnd)) return ErrorLevel := "ERROR" if (window="desktop") { ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman if !hwWindow ; #D mode ControlGet, hwWindow, HWND,, SysListView321, A ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow% base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop Loop, Parse, files, `n, `r { path := base "\" A_LoopField IfExist %path% ; ignore special icons like Computer (at least for now) ret .= path "`n" } } else { if selection collection := window.document.SelectedItems else collection := window.document.Folder.Items for item in collection ret .= item.path "`n" } return Trim(ret,"`n") }
转载自:http://wjason.iteye.com/blog/1955712
相关文章推荐
- Android 通过文件管理器选择文件夹下面的文件以及获取路径
- WPF 获取文件夹路径,目录路径,复制文件,选择下载文件夹/目录
- java如何实现在系统资源管理器中选中指定文件/文件夹?
- Win32 API 选择文件和文件夹
- Eclipse RCP中获取Plugin/Bundle中文件资源的绝对路径(转载)
- 获取一个文件夹下子文件 路径名
- eclipse中文件文件夹高速定位,打开文件所在文件夹,在资源管理器中查看
- java中获取文件或文件夹的路径方法
- rcp(插件开发)获取Plugin/Bundle中文件资源的绝对路径
- C# 获取文件夹路径和文件夹包含文件列表
- 使用API获取内部存储文件的路径;外部存储
- JavaWeb中获取资源文件路径
- java路径以及获取资源文件的方法
- .NET中获取指定文件夹下所有文件的全路径
- Java实现获取Web上所有路径下资源文件的URL地址
- JAVA 一个简单的文件写入代码(遍历文件夹获取所有文件、写入缓冲池、获取文件绝对路径、按后缀名过滤文件)
- Spring 获取资源文件路径
- iphone开发中获取Documents文件夹和资源文件夹路径
- VC++ API 如何获取文件夹路径
- python 从一个文件夹下获取所有的文件的路径