Jump to content

Get full path of file selected in explorer


 Share

Recommended Posts

I'm working on a replacement program for the default windows copy-paste copying program but I've run into some problems.

I just can't get my head around getting the full path of a file in explorer.

My current code actually gets the name of the item and that works great on my system since I have turned on show file endings in explorers options.

I have some running code that sends ctrl+c and then use ClipGet() to get the path, but I don't like that options because it partly interfere with the original purpose of my script.

My Current Code:

#include <WINAPI.au3>
#include <Process.au3>
#include <GUIListView.au3>
#include <Array.au3>
Global $CopyHotKey = "^c"

HotKeySet($CopyHotKey, "_Copy")


Do
    Sleep(100)
Until False

Func _Copy()
    $handle = WinGetHandle("")
    $pid = WinGetProcess($handle)
    Local $tocopy[1]
    If _ProcessGetName($pid) = "explorer.exe" Then
        $chandle=ControlGetHandle($handle,"","[CLASSNN:SysListView321]")
        
        For $i=0 To _GUICtrlListView_GetItemCount($chandle)-1
            
            If _GUICtrlListView_GetItemState ($chandle,$i,$LVIS_SELECTED)=$LVIS_SELECTED Then
            MsgBox(0,"",_GUICtrlListView_GetItemText($chandle,$i))
            EndIf
            
        Next
    Else
        HotKeySet($CopyHotKey)
        Send("^c")
        HotKeySet($CopyHotKey, "_Copy")
    EndIf


    
EndFunc  ;==>_Copy

Thanks in advance!

;)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I'm working on a replacement program for the default windows copy-paste copying program but I've run into some problems.

I just can't get my head around getting the full path of a file in explorer.

My current code actually gets the name of the item and that works great on my system since I have turned on show file endings in explorers options.

I have some running code that sends ctrl+c and then use ClipGet() to get the path, but I don't like that options because it partly interfere with the original purpose of my script.

My Current Code:

#include <WINAPI.au3>
#include <Process.au3>
#include <GUIListView.au3>
#include <Array.au3>
Global $CopyHotKey = "^c"

HotKeySet($CopyHotKey, "_Copy")


Do
    Sleep(100)
Until False

Func _Copy()
    $handle = WinGetHandle("")
    $pid = WinGetProcess($handle)
    Local $tocopy[1]
    If _ProcessGetName($pid) = "explorer.exe" Then
        $chandle=ControlGetHandle($handle,"","[CLASSNN:SysListView321]")
        
        For $i=0 To _GUICtrlListView_GetItemCount($chandle)-1
            
            If _GUICtrlListView_GetItemState ($chandle,$i,$LVIS_SELECTED)=$LVIS_SELECTED Then
            MsgBox(0,"",_GUICtrlListView_GetItemText($chandle,$i))
            EndIf
            
        Next
    Else
        HotKeySet($CopyHotKey)
        Send("^c")
        HotKeySet($CopyHotKey, "_Copy")
    EndIf


    
EndFunc;==>_Copy

Thanks in advance!

;)

This seems to work

#include <WINAPI.au3>
#include <Process.au3>
#include <GUIListView.au3>
#include <Array.au3>
Global $CopyHotKey = "^c"

HotKeySet($CopyHotKey, "_Copy")


Do
    Sleep(100)
Until False

Func _Copy()
    $handle = WinGetHandle("")
    $pid = WinGetProcess($handle)
    Local $tocopy[1]
;ConsoleWrite( _ProcessGetName($pid) & @CRLF)
    If _ProcessGetName($pid) = "explorer.exe" Then
        $chandle=ControlGetHandle($handle,"","[CLASS:SysListView32;INSTANCE:1]")
;ConsoleWrite("no of items = " & _GUICtrlListView_GetItemCount($chandle) & @CRLF)
        For $i=0 To _GUICtrlListView_GetItemCount($chandle)-1
            
            If _GUICtrlListView_GetItemState ($chandle,$i,$LVIS_SELECTED)=$LVIS_SELECTED Then
            MsgBox(0,"",_GUICtrlListView_GetItemText($chandle,$i))
            EndIf
            
        Next
    Else
        HotKeySet($CopyHotKey)
        Send("^c")
        HotKeySet($CopyHotKey, "_Copy")
    EndIf


    
EndFunc;==>_Copy
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yeah, but if you have selected not to show the file endings then if I select test.mp3 only test shows up ;)

Umm, some people are difficult to please :D

You could make your script set the options to view extensions.

Presumably if you send ^c the full information on the file is in the clipboard or else how does explorer know what to paste, so perhaps it's just a question of finding some way to read what's in the clipboard.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Umm, some people are difficult to please :D

You could make your script set the options to view extensions.

Presumably if you send ^c the full information on the file is in the clipboard or else how does explorer know what to paste, so perhaps it's just a question of finding some way to read what's in the clipboard.

I know I actually made a function that gets the information that way, but I was just wondering if there was another way to do it. It would be great if I could avoid using the clipboard at all ;)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I know I actually made a function that gets the information that way, but I was just wondering if there was another way to do it. It would be great if I could avoid using the clipboard at all ;)

If you are right clicking in Explorer to do the Copy Paste then you should be able to use the Shell extension mechanism to get the complete path of the selected file(s). AutoIt3 probably isn't the best choice for shell extensions though. VC++ 6 is much easier for this purpose. Esp. since you can get code generators from

Code Project for Context Menu Handlers etc..

To learn more about shell extensions go to code project and search on keywords

Idiot's Guide Shell Extension and a bunch of very good articles come up. Also somebody

made a wizard if you have VC++ 6 Professional that generates skeleton code for various

shell extension type handlers. Doing it from scratch is very frustrating but if you can go

from skeleton code you just make a simple test dll that works, then go back and fill in the

real code to do the job. They are kind of fun once you get some of them going. :D

Link to comment
Share on other sites

I have an Idea (maybe a stupid one):

$thefilename = "your_file_without_ext"

FileFindFirstFile("C:\path\" & $thefilename & ".*")

and so on...

you could try and get the file that way ;)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

If you are right clicking in Explorer to do the Copy Paste then you should be able to use the Shell extension mechanism to get the complete path of the selected file(s). AutoIt3 probably isn't the best choice for shell extensions though. VC++ 6 is much easier for this purpose. Esp. since you can get code generators from

Code Project for Context Menu Handlers etc..

To learn more about shell extensions go to code project and search on keywords

Idiot's Guide Shell Extension and a bunch of very good articles come up. Also somebody

made a wizard if you have VC++ 6 Professional that generates skeleton code for various

shell extension type handlers. Doing it from scratch is very frustrating but if you can go

from skeleton code you just make a simple test dll that works, then go back and fill in the

real code to do the job. They are kind of fun once you get some of them going. ;)

It's not at all difficult to add extensions like that and it doesn't need anything fancy.

$KeyName = "file extras"
$ContextMenuName = "Get file details";the menu item text
$ProgramToRun = @SystemDir & "\monoceres.exe"; program to run when option is clicked
RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $KeyName & "\command", '', 'REG_SZ', '"' & $ProgramToRun & '" "%1"');'passes file full path to program
RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $KeyName, '', 'REG_SZ', $ContextMenuName)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

If you are right clicking in Explorer to do the Copy Paste then you should be able to use the Shell extension mechanism to get the complete path of the selected file(s). AutoIt3 probably isn't the best choice for shell extensions though. VC++ 6 is much easier for this purpose. Esp. since you can get code generators from

Code Project for Context Menu Handlers etc..

To learn more about shell extensions go to code project and search on keywords

Idiot's Guide Shell Extension and a bunch of very good articles come up. Also somebody

made a wizard if you have VC++ 6 Professional that generates skeleton code for various

shell extension type handlers. Doing it from scratch is very frustrating but if you can go

from skeleton code you just make a simple test dll that works, then go back and fill in the

real code to do the job. They are kind of fun once you get some of them going. ;)

Thanks, I will search around and see what I can found. You don't know any article do you? I only seem to find articles about building my own, not interacting with others.

I have an Idea (maybe a stupid one):

$thefilename = "your_file_without_ext"

FileFindFirstFile("C:\path\" & $thefilename & ".*")

and so on...

you could try and get the file that way ;)

That won't very well. There could be files with the same first letters and different file endings. Like hello.wav and hello.mp3.

Thanks anyway :D

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

It's not at all difficult to add extensions like that and it doesn't need anything fancy.

$KeyName = "file extras"
 $ContextMenuName = "Get file details";the menu item text
 $ProgramToRun = @SystemDir & "\monoceres.exe"; program to run when option is clicked
 RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $KeyName & "\command", '', 'REG_SZ', '"' & $ProgramToRun & '" "%1"');'passes file full path to program
 RegWrite("HKEY_CLASSES_ROOT\*\shell\" & $KeyName, '', 'REG_SZ', $ContextMenuName)
Now I understand, so the next question is rather obvious... do you know how to click the Context Menu item that is created without the user seeing everything?

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

I'm working on a replacement program for the default windows copy-paste copying program but I've run into some problems.

I just can't get my head around getting the full path of a file in explorer.

My current code actually gets the name of the item and that works great on my system since I have turned on show file endings in explorers options.

I have some running code that sends ctrl+c and then use ClipGet() to get the path, but I don't like that options because it partly interfere with the original purpose of my script.

Not sure if it'll handle exactly what you're trying to do, but I've got a right-click (context menu) utility method written in AutoIt available -> here.

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Thanks, I will search around and see what I can found. You don't know any article do you? I only seem to find articles about building my own, not interacting with others.

I don't know how you could replace the shell copy/paste without rolling your own .dll.

The best chance for an AutoIt implementation may be if there's something in ActiveX

I haven't messed around with any ActiveX in AutoIt yet so I'm not sure what's there.

Hooking script into the explorer shell is generally not a good idea as errors tend to

make the shell restart. Usually better to have a dll do the interaction and it can call

some other exe to do the dirty work.

For context menu as example, every time you right click the explorer items that fit

whatever you registered the shell handler for, it's going to call you with an init call

and hand you the filename or list of items selected, then if things proceed from there,

it calls to let you add commands or submenus to the context menu. Then if a command

is selected, it calls your dll yet again to execute the command. Lots of handlers are

being loaded queried etc.. by the shell so anything slow or fragile shouldn't be hooking

into it.

Link to comment
Share on other sites

  • 1 month later...

Maybe this one can help:

#include <Array.au3>

$aSelected_Info = _ExplorerGetSelectedItems()
If @error Then Exit MsgBox(48, "Error", "There is no selected items." & @LF & @LF & "OK ==> EXIT")

_ArrayDisplay($aSelected_Info) 

;[0][0] = Total items count
;[N][0] = Selected element Index
;[N][1] = Selected element is Directory
;[N][2] = Selected element string (full path to the file/dir)
Func _ExplorerGetSelectedItems($sCabinetWClass="[CLASS:CabinetWClass]")
    Local $aRetInfo[1][1]
    Local $aIndexes, $iIndex, $iCount, $sSelected, $sSelected_Path
    Local $hSearch, $sCurrentFile
    
    $sSelected_Path = ControlGetText($sCabinetWClass, "", "Edit1")
    $aIndexes = StringSplit(ControlListView($sCabinetWClass, "", "SysListView321", "GetSelected", 1), "|")
    
    If $aIndexes[0] = 1 And $aIndexes[1] = "" Then Return SetError(1, 0, 0)
    
    For $i = 1 To $aIndexes[0]
        $sSelected = ControlListView($sCabinetWClass, "", "SysListView321", "GetText", $aIndexes[$i])
        $sCurrentFile = $sSelected_Path & "\" & $sSelected
        
        If Not FileExists($sCurrentFile) Then ;Search the extension for file...
            $hSearch = FileFindFirstFile($sCurrentFile & ".*")
            
            If $hSearch <> -1 Then
                $sCurrentFile = $sSelected_Path & "\" & FileFindNextFile($hSearch)
                FileClose($hSearch)
            EndIf
        EndIf
        
        $aRetInfo[0][0] += 1
        ReDim $aRetInfo[$aRetInfo[0][0]+1][3]
        
        $aRetInfo[$aRetInfo[0][0]][0] = $aIndexes[$i] ;Index
        $aRetInfo[$aRetInfo[0][0]][1] = Number(StringInStr(FileGetAttrib($sCurrentFile), "D") > 0) ;Is Directory
        $aRetInfo[$aRetInfo[0][0]][2] = $sCurrentFile ;Selected file / dir
    Next
    
    If $aRetInfo[0][0] = 0 Then Return SetError(2, 0, 0)
    
    Return $aRetInfo
EndFunc

:P

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...