spuuunit Posted July 5, 2020 Share Posted July 5, 2020 I want to be able to detect the path to the selected files / folders in file explorer, or the Desktop if that is active instead. I have a script that only get the names of the Desktop files selected. This is a problem since that name could be pic, but maybe I have pic.jpg and pic.png, then which is it? And I don't know how to do it in file explorer at all. This is my script: Sleep(3000) If WinActive("[CLASS:Progman]") Then ; DESKTOP $ids = ControlListView("[CLASS:Progman]", "", 1, "GetSelected", 1) $id = StringSplit($ids, "|") ; start at 1 local $name[Ubound($id)] For $i = 1 to Ubound($id) - 1 $name[$i] = ControlListView("[CLASS:Progman]", "", 1, "GetText", $id[$i]) Next $msgbox = "" For $i = 1 to Ubound($id) - 1 $msgbox = $msgbox & $name[$i] & @CRLF Next MsgBox(0, "", $msgbox) ElseIf WinActive("[CLASS:CabinetWClass]") Then ; EXPLORER $ids = ControlListView("[CLASS:CabinetWClass]", "", 1, "GetSelected", 1) MsgBox(0, "doesnt work", $ids) EndIf Link to comment Share on other sites More sharing options...
seadoggie01 Posted July 6, 2020 Share Posted July 6, 2020 LarsJ has a UDF for this as well as an example at the top that looks like it does exactly what you're going for See if this works for you! All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
KaFu Posted July 6, 2020 Share Posted July 6, 2020 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
careca Posted July 6, 2020 Share Posted July 6, 2020 When you select files and copy, the full path is put in the clipboard, so maybe you could select, press a key and grab the paths in clipboard. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
spuuunit Posted July 6, 2020 Author Share Posted July 6, 2020 4 hours ago, careca said: When you select files and copy, the full path is put in the clipboard, so maybe you could select, press a key and grab the paths in clipboard. Thanks, a smart tip. But not in my situation unfortunately. Link to comment Share on other sites More sharing options...
spuuunit Posted July 6, 2020 Author Share Posted July 6, 2020 (edited) 8 hours ago, seadoggie01 said: LarsJ has a UDF for this as well as an example at the top that looks like it does exactly what you're going for See if this works for you! 8 hours ago, KaFu said: Great examples both of them! With both examples I could print out the selected files. Thanks! But none of them work on the Desktop. The closest I get is with this code, but I only get the name without extension ( pic and not pic.jpg ) $ids = ControlListView("[CLASS:Progman]", "", 1, "GetSelected", 1) $id = StringSplit($ids, "|") For $i = 1 to Ubound($id) - 1 MsgBox(0, "", ControlListView("[CLASS:Progman]", "", 1, "GetText", $id[$i])) Next Edited July 6, 2020 by spuuunit Link to comment Share on other sites More sharing options...
seadoggie01 Posted July 7, 2020 Share Posted July 7, 2020 Are you talking about when you navigate to the desktop folder via File Explorer, or that you have icons selected on your desktop? All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
spuuunit Posted July 7, 2020 Author Share Posted July 7, 2020 When I have icons selected on my desktop. Link to comment Share on other sites More sharing options...
careca Posted July 7, 2020 Share Posted July 7, 2020 $clip = ClipGet() $split = StringSplit($clip, @LF, 1) For $i = 1 to $split[0] MsgBox(64 + 262144, $i, $split[$i]) Next So you select and copy, then run this, or maybe, run in background and trigger with a key. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
spuuunit Posted July 7, 2020 Author Share Posted July 7, 2020 8 hours ago, careca said: $clip = ClipGet() $split = StringSplit($clip, @LF, 1) For $i = 1 to $split[0] MsgBox(64 + 262144, $i, $split[$i]) Next So you select and copy, then run this, or maybe, run in background and trigger with a key. Sorry but I really want to avoid copying the files. It's hard to explain, but it's not a good idea in my situation. Thanks anyway! Is there any other way of doing this (get path of selected files on the desktop)? Link to comment Share on other sites More sharing options...
seadoggie01 Posted July 7, 2020 Share Posted July 7, 2020 Almost never should you ask "is there" in programming, but instead ask, "how?" expandcollapse popupMain() Func Main() Local $hDesktop = WinWait("[TITLE:Program Manager;CLASS:Progman]") Local $ids = ControlListView($hDesktop, "", "[CLASS:SysListView32; INSTANCE:1]", "GetSelected", 1) Local $aItems = StringSplit($ids, "|", 3) Local $sFile, $sFullFile For $i = 0 to Ubound($aItems) - 1 $sFile = ControlListView($hDesktop, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i]) ; Get the full name of the file $sFullFile = FindFile(@DesktopDir, $sFile) ; If there were multiple files found If @extended Then ConsoleWrite("Multiple files found: " & $sFullFile & @CRLF) Else ConsoleWrite("Selected file: " & $sFullFile & @CRLF) EndIf Next EndFunc Func FindFile($sFolder, $sFile) Local $hSearch = FileFindFirstFile($sFolder & "\" & $sFile & "*") If @error Then Return SetError(1, 0, False) ; Get the first file from the search Local $sRet = FileFindNextFile($hSearch) Local $sExtras = "" While True $sExtras &= FileFindNextFile($hSearch) If @error Then ExitLoop WEnd ; If there were extra files If $sExtras <> "" Then Return SetExtended(1, $sRet & $sExtras) Return $sRet EndFunc (I changed a bit of your code because it wasn't running on my computer, then i remembered that I run x64 by default, but AutoIt doesn't. I also used different variable names.) The important bit is the FindFile function. It takes a folder and file and finds all files that match that name with any ending (.txt, .xlsx, etc). All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
spuuunit Posted July 7, 2020 Author Share Posted July 7, 2020 26 minutes ago, seadoggie01 said: Almost never should you ask "is there" in programming, but instead ask, "how?" expandcollapse popupMain() Func Main() Local $hDesktop = WinWait("[TITLE:Program Manager;CLASS:Progman]") Local $ids = ControlListView($hDesktop, "", "[CLASS:SysListView32; INSTANCE:1]", "GetSelected", 1) Local $aItems = StringSplit($ids, "|", 3) Local $sFile, $sFullFile For $i = 0 to Ubound($aItems) - 1 $sFile = ControlListView($hDesktop, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i]) ; Get the full name of the file $sFullFile = FindFile(@DesktopDir, $sFile) ; If there were multiple files found If @extended Then ConsoleWrite("Multiple files found: " & $sFullFile & @CRLF) Else ConsoleWrite("Selected file: " & $sFullFile & @CRLF) EndIf Next EndFunc Func FindFile($sFolder, $sFile) Local $hSearch = FileFindFirstFile($sFolder & "\" & $sFile & "*") If @error Then Return SetError(1, 0, False) ; Get the first file from the search Local $sRet = FileFindNextFile($hSearch) Local $sExtras = "" While True $sExtras &= FileFindNextFile($hSearch) If @error Then ExitLoop WEnd ; If there were extra files If $sExtras <> "" Then Return SetExtended(1, $sRet & $sExtras) Return $sRet EndFunc (I changed a bit of your code because it wasn't running on my computer, then i remembered that I run x64 by default, but AutoIt doesn't. I also used different variable names.) The important bit is the FindFile function. It takes a folder and file and finds all files that match that name with any ending (.txt, .xlsx, etc). Thanks! But it would be great if it could know which one it is if there is multiples (for example I select pic.jpg, but there is also pic.gif). How do I do that? Link to comment Share on other sites More sharing options...
seadoggie01 Posted July 7, 2020 Share Posted July 7, 2020 Lol I personally check the option in File Explorer for View -> Show/hide -> File name extensions. With that checked, your original selection will return pic.jpg or pic.gif. Other than that, I don't know. I'm sure there's a way to do this, and you might need to ping LarsJ to get him on this All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
spuuunit Posted July 7, 2020 Author Share Posted July 7, 2020 Interesting! But I don't like to have that on, so no good for me I'm afraid. Good idea, I'll try asking LarsJ. Thanks for all your help! If I manage to get it working I'll post the code here, for anyone else who's interested. Link to comment Share on other sites More sharing options...
LarsJ Posted July 8, 2020 Share Posted July 8, 2020 See this example. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
spuuunit Posted July 8, 2020 Author Share Posted July 8, 2020 1 hour ago, LarsJ said: See this example. You, are a legend my friend. Thank you so much for this! I'll post your example for my issue here for anyone to see ( of course you'll need LarsJ's included FileExplorer.au3 too ) : expandcollapse popup#include "..\..\Includes\FileExplorer.au3" #include <Array.au3> Example() Func Example() ; Desktop on Windows 7, 8, 10 ;Local $hExplorer = WinGetHandle( "[CLASS:Progman]" ) Local $hExplorer = _WinAPI_GetDesktopWindow() If Not $hExplorer Then MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." ) Return EndIf ; Get an IShellBrowser interface GetIShellBrowser( $hExplorer ) If Not IsObj( $oIShellBrowser ) Then MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." ) Return EndIf Local $objShell = ObjCreate( "shell.application" ) $objShell.ToggleDesktop ; Get other interfaces GetShellInterfaces() ; Get all files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aFiles = GetFiles( False, True ) _ArrayDisplay( $aFiles, "All files" ) ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) $aFiles = GetFiles( True, True ) _ArrayDisplay( $aFiles, "Selected files" ) EndFunc Again, thanks a lot. Your Windows handling stuff is amazing! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now