From Explorer, get the API for the path (and folder) of the selected file

Source: Internet
Author: User
Tags stringreplace

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.