Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How To] Retrieve File fullpath from Explorer


  • Please log in to reply
22 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

How to retrieve File fullpath from Explorer ?
http://www.autohotke...p?p=86542#86542

Foreword: I was trying to help Zak M. in the Ask for Help Topic: Select a file and copy its location and my find is very helpful for me too! I thank him for that! :D


Solution: Create a "Drag and Drop" enabled GUI and drag the files to it with MouseClickDrag . Handle the retrieved full path of file(s) in GuiDropFiles label as required.

The title of this post might sound tricky, as I have mentioned it as "Explorer" instead of "Windows Explorer". It is so because this trick applies to any iconic file visible to naked eyes, Like:

TreeView & List View and Addess bar icon in "Windows Explorer"
Files on the Desktop
Shortcut links on the Quick Launch
File Open / Save DialogHere is a basic example:

SetBatchLines, -1
SetBatchLines, 1
CoordMode, Mouse, Screen

Gui, +AlwaysOnTop -Caption +Border +ToolWindow
Gui, Show, x0 y0 w9 h9 Hide, AHK.WE2CB.DND.GUI 
Return 

#LButton::
 MouseGetPos, X, Y
 GuiX := X-30
 GuiY := Y-30
 Gui, Show, x%GuiX% y%GuiY%
 MouseClickDrag, Left,,, GuiX+3, GuiY+3, 0
 MouseMove, X, Y
 Gui, Hide
Return

GuiDropFiles: 
 ClipBoard := A_GuiControlEvent
Return


Run the above code and with Winkey down, Left click on a file. The file's fullpath will be copied to the clipboard. If multiple files were selected, Clipboard will contain the file list delimited with `n ( Linefeed)

Since the above uses Gui, Show after a click, It will not work with Start Menu (which disappears before the drag could be performed). But I am sure it worked for me in a one of my experimental variants which I unfortunately do not remember!

So, this method works almost everywhere, to be precise, everywhere where you get a right click context menu for a Iconic file.

Here is a improvised version that should go into my always-running-script!

SetBatchLines, -1 
SetBatchLines, 1 
CoordMode, Mouse, Screen 
CoordMode, Tooltip, Screen 

Menu, Tray, Icon, Clipbrd.exe,2 
Gui, +AlwaysOnTop -Caption +ToolWindow 
Gui, Color, EEAA99 
Gui +LastFound  
WinSet, TransColor, EEAA99 
Gui, Add, Picture, x0 y0 w32 h32 vICO1 Icon1 , Clipbrd.exe 
Gui, Add, Picture, x0 y0 w32 h32 vICO2 Icon2 , Clipbrd.exe 
Gui, Show, x0 y0 w32 h32 Hide, AHK.WE2CB.DND.GUI 
Return 

#LButton:: 

 Loop { 
        LBDown := GetKeyState("LButton","P") 
        IfEqual, LBDown, 0, Break 
      } 
 MouseGetPos, X, Y 
 GuiX := X-50 
 GuiY := Y-50 
 GuiControl, Show, ICO1 
 Gui, Show, x%GuiX% y%GuiY% 
 MouseClickDrag, Left,,, GuiX+16, GuiY+16, 0 
 MouseMove, X, Y 
 GoSub, ToolTip 
Return 

GuiDropFiles: 

 GuiControl, HIDE, ICO2 
 FileFullPath := A_GuiControlEvent 
 StringReplace, FileFullPath, FileFullPath, `n,`n, All UseErrorLevel 
 If (ErrorLevel < 1) { 
    StringRight, Extn, FileFullPath, 3 
    StringUpper, Extn, Extn 
[color=brown]    IfEqual,Extn,LNK, FileGetShortcut,%FileFullPath%, FileFullPath 
    IfEqual,Extn,URL, IniRead,FileFullPath,%FileFullPath%,InternetShortCut,URL[/color]
                     } 
 Clipboard := FileFullPath 
Return 

ToolTip: 
 SetTimer, ToolTip, Off 
 ToolTip, % ClipBoard, GuiX+37, GuiY+6 
 Loop { 
       WinKeyDown := GetKeyState("LWin","P") 
       IfEqual, WinKeyDown, 0, Break 
      } 
ToolTip 
GuiControl, Show, ICO2 
Gui, Hide 
Return

Run the code. Press Windows Key and without releasing it left-click on an icon. The clipboard data will be shown as a tooltip as long as the Windows key is held down. For Quick Launch icons ( and other shotcuts too ), the actual path to the target file is retrieved.

Snapshots:

Retrieving the Target file from Quick Launch Icon

Posted Image


Retrieving fullpath from Windows Explorer List View

Posted Image


Retrieving fullpath from Windows Explorer TreeView

Posted Image


What really excites me is the fact that we do not have to mess with registry for defining context menus anymore.

8)


Perform Hash sum calculation for a file, calling it from a simulated context menu

Snapshots of the result:

Posted Image

Posted Image
This script requires hashes.dll to be present in the script's folder. You have to download hashes_dll.zip [45k] and extract hashes.dll from it.. Run the following script and Left-Click on a file with Winkey as a modifier:

SetBatchLines, -1 
SetBatchLines, 1 
SetWorkingDir, %A_ScriptDir%
CoordMode, Mouse, Screen 

Hs:="MD2|MD4|MD5||SHA1|SHA256|SHA384|SHA512||HAVAL128|HAVAL160|HAVAL192|HAVAL224|"
  . "HAVAL256||GHOST||TIGER128|TIGER160|TIGER192||RIPE-MD128|RIPE-MD160||CRC32|CRC16"

Loop, PARSE, Hs, |
      Menu, HashesMenu, Add, %A_LoopField%, CalculateHash

Gui, +AlwaysOnTop -Caption +Border +ToolWindow 
Gui, Show, x0 y0 w9 h9 Hide, AHK.WE2CB.DND.GUI 
Return 

#LButton:: 
 MouseGetPos, X, Y 
 GuiX := X-50
 GuiY := Y-50
 Gui, Show, x%GuiX% y%GuiY% 
 MouseClickDrag, Left,,, GuiX+5, GuiY+5, 0 
Return 

GuiDropFiles: 
 Gui, Show, Hide
 MouseMove, X, Y 
 FileFullPath := A_GuiControlEvent 
 StringSplit, MFile, FileFullPath, `n
 Menu, HashesMenu, Show
Return

CalculateHash:
 Hash := DllCall("hashes.dll\testit", Str,MFile1, Str,A_ThisMenuItem, Int,0, Str) 
 StringTrimRight, Hash, Hash, 68   
 SplitPath, MFile1, FileName
 MsgBox,4100,%MFile1%, % A_ThisMenuItem ": " Hash "`n`nCOPY hash to Clipboard?", 10
 IfMsgBox, Yes, SetEnv, ClipBoard, %Hash%
Return



SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
A small update has been done to the above script:

IfEqual,Extn,URL, IniRead,FileFullPath,%FileFullPath%,InternetShortCut,URL

For URL Shortcut files, the URL will be copied to the clipboard.

:)
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Very good Goyyah, very good.

It is pretty big trouble getting the path using API. This is excellent solution. I didnt test it as my computer is down, but I hope it doesnt have some flickering sideeffects or something due to the fact that drag&drop is used.

Your conclusion about context menus is good, but you didn't realise one thing. Using registry U can setup only static extensions. Contrary to that, dynamic extension must be registred as COM object on several places in registry and must be in dll, so to receive file name BEFORE it adds extension to the list for that file. As we can now have good way to obtain the path of the file we can create dynamic enteries that depend on file contest, type etc....
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Ah, now I see it cant be used as general method as you are depending on mouse position ....

You also have my method to get current directory in Explorer, OpenSave and BrowseForFolder system windows. I didn't need selected file name, but that can be easily obtained from the listview. It doesn't need mouse to get selection. The code is available in Favmenu script .


Snuping around I also found an undocumented Windows Message called CWM_GETPATH. You can take a look here. I will cerntanly update Favmenu with this if it works.

This is also nice tutorial

Nice sideffect of the search is this
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Snuping around I also found an undocumented Windows Message called CWM_GETPATH.

Sound familiar... Get the current path of a Window Explorer
Alas, being undocumented, it isn't very reliable, as it seems.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Alas, being undocumented, it isn't very reliable, as it seems.

I don't think so.
It may be not reliable cuz of lack of documentation though.
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
My wording was poor. I meant it is based on undocumented functions/messages, and as such, Microsoft doesn't guarantee any present, past or future support for this. And it seems that the Win98 part doesn't work, and it doesn't work on Win2k either. Might be broken in Vista as well. So it is more or less a WinXP trick, where it can be reliable, hopefully.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor !
  • Guests
  • Last active:
  • Joined: --
The site I was looking on was Undocumented Win98, witch meens it works there. The man also stated that everything works in NT system, witch menas it must work in 2k. There might be some other kind of a problem in the function you wrote. I doubt that microsoft will remove such functions as they know people use them alot. Almost everything undocumented is documented somewhere by entusiastics and even some books are written about so called Native API calls (different then API visible to programmers).

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

There might be some other kind of a problem in the function you wrote.

Maybe. I welcome any further tests and improvements by whoever want to look at it. Goyyah, you have a Win2k computer, did you tested my function? I tested on Win98, and somebody else did.

I doubt that microsoft will remove such functions as they know people use them alot.

You are optimistic... MS doesn't hesitate to drop documented functions (or list them as deprecated, and remove any doc. on them), so I don't doubt they would remove these functions without even blinking if they think it is good for them.
There are still lot of people using Win9x and WinNT 4 computers, but they no longer support them. They don't look back...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor !
  • Guests
  • Last active:
  • Joined: --

MS doesn't hesitate to drop documented functions (or list them as deprecated, and remove any doc. on them),

That "or" makes the difference ! They mark functions as obsolated every now and then but I have never encountered "missing function".

I like this method as any other is much more complicatedl So it would be good to find errors in your function and to make it work for sure. I don't use Win9x system and don't want to support them in my programming but Win2k is different thing.... Goyyah, you should test it on 2k if you have any...

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear majkinetor/PhiLho, :)

Many thanks for the feedback! The day was hectic for me, and I could not take much time on the computer yesterday.

It is pretty big trouble getting the path using API. This is excellent solution. I didnt test it as my computer is down, but I hope it doesnt have some flickering sideeffects or something due to the fact that drag&drop is used.
...
Ah, now I see it cant be used as general method as you are depending on mouse position ....


Thanks .. Yes.. this is a not-so-elegant solution but still I have a common code that works in Win2K & Win XP for me without messing with the registry.

I have update the main post with an example:
Perform Hash sum calculation for a file, calling it from a simulated context menu

That kind of facility was what I was excited about. I have been using a third party software ( I had to install it! ) for calculating MD5 hash. Now I have more hash options and the results are perfectly customised for my needs! :D

I welcome any further tests and improvements by whoever want to look at it. Goyyah, you have a Win2k computer, did you tested my function? I tested on Win98, and somebody else did.


I do not remember on whether I tried it when you had posted it. But I tried it now and get empty results :roll: . Let me not be hasty, I will check it again and post again in that topic. :)

I don't use Win9x system and don't want to support them in my programming but Win2k is different thing.... Goyyah, you should test it on 2k if you have any...


Sure .. Please allow me time.. I have just logged on.. :)
I will try it and bump your topic. :)

Meanwhile, I am thinking of erecting an outdated system ( I have a huge pile of hardware ) with Win95 OSR2 & Win98 SE - only for testing the compatiblity issues!

Many Regards, :)
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Meanwhile, I am thinking of erecting an outdated system

You can do it on your currrent system usinig Virutal Machine.
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

You can do it on your currrent system usinig Virutal Machine.

If you know a good (stable) free one, tell us! :-)
Oh, I just recall that Microsoft has bought recently Virtual PC and made it free... Did you tried it?
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Nope, I use vmware for now.
I hear that Virutal PC is very similar.
Posted Image

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Meanwhile, I am thinking of erecting an outdated system

You can do it on your currrent system usinig Virutal Machine.


I wanted to erect a seperate system for my 19 month old son who plays on my system as though it was a toy. :D. I just want to put Win98 SE and an AHK script that would show the keypressed as a FullScreen Bitmap. ( Maybe with corresponding .WAV )

Just thought, he would not mind if I borrowed it for testing my code - once a while.

:)
kWo4Lk1.png