The library is obtained from the URL below.
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 ActiveWindow would be used). Requires ahk_l or similar. Works with the desktop. Does not currently work with savedialogs and such. Explorer_getselected (hwnd= "")-Paths of target window ' s selected Itemsexplorer_getall (hwnd= "")-Paths of all it EMS in the target window ' s Folderexplorer_getpath (hwnd= "")-Path of target window ' s folderexample:f1::p ath: = Explo Rer_getpath () All: = Explorer_getall () Sel: = explorer_getselected () MsgBox% pathmsgbox% allmsgbox% selreturn Joshua A. Kinnison2011-04-27, 16:12*/explorer_getpath (hwnd= "") {if! ( window: = Explorer_getwindow (hwnd)) return ErrorLevel: = "ERROR" if (window= "desktop") return A_desktoppath: = window. Locationurlpath: = regexreplace (Path, "ftp://.*@", "ftp://") stringreplace, Path, path, file:///StringReplace, Path, Path,/,\, all; Thanks to Polyetheneloopif regexmatch (path, "i) (? <=%) [\da-f]{1,2}", hex) stringreplace, path, path, '%%hex%,% Chr ("0x " . hex), Allelse breakreturn 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") Returnif (Class ~= "(cabinet| Explore) {Wclass ") {for Windows in Comobjcreate (" Shell.Application "). WindowsIf (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 progmanif!hwwindow; #D Modecontrolget, Hwwindow, HWND,, SysListView321, acontrolget, files, List,% (selection? The SelectEd ":") "Col1", ahk_id%hwwindow%base: = SubStr (a_desktop,0,1) = = "\"? SUBSTR (a_desktop,1,-1): A_desktoploop, Parse, files, ' N, ' r{path: = base "\" a_loopfieldifexist%path%; Ignore special I Cons like computer (at least for now) ret. = Path "' N"}}else{if selectioncollection: = Window.document.SelectedItemselsecol Lection: = window.document.Folder.Itemsfor item in Collectionret. = Item.path "' N"}return Trim (ret, "' N")}
Reprinted from:http://wjason.iteye.com/blog/1955712
From Explorer, get the API for the path (and folder) of the selected file