Select Folder with exact name Topic is solved
Select Folder with exact name
Hello,
Sorry if this is too much but I don't know where to start.
I'm trying to write a script that selects a folder based on a selected file name.
In other words, when I choose a file 'name.jpg', the script adds a folder called "name" to the selection. Searching only in the same folder.
The reason for this is to cut and paste both of them to a different location.
Any help really appreciated.
Thank you,
Artur
Sorry if this is too much but I don't know where to start.
I'm trying to write a script that selects a folder based on a selected file name.
In other words, when I choose a file 'name.jpg', the script adds a folder called "name" to the selection. Searching only in the same folder.
The reason for this is to cut and paste both of them to a different location.
Any help really appreciated.
Thank you,
Artur
Re: Select Folder with exact name
Welcome to this AutoHotkey forum!
Code: Select all
Run, explorer
#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe
F3::
file := getSelected().1
SplitPath, file, fn, dir,, fnBare
file := dir "\" fnBare "\" fn
MsgBox, %file%
Return
#IfWinActive
getSelected() {
; Adapted: https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
hwnd := WinExist("A"), selection := []
WinGetClass, class
If (class ~= "(Cabinet|Explore)WClass")
For window in ComObjCreate("Shell.Application").Windows
If (window.hwnd = hwnd)
For item in window.document.SelectedItems
selection.Push(item.Path)
Return selection
}
Re: Select Folder with exact name
Wow, that's a super swift reply!
Thank you for such a warm welcome
Thank you for such a warm welcome
Re: Select Folder with exact name
May I ask for some additional help?
I'm running the script and it opens windows explorer. I'm navigating to my database folder but nothing happens when I click a file (even though, there are folders with the same name).
Do I need to adjust the script, or am I failing to run it properly?
Artur
I'm running the script and it opens windows explorer. I'm navigating to my database folder but nothing happens when I click a file (even though, there are folders with the same name).
Do I need to adjust the script, or am I failing to run it properly?
Thank you,mikeyww wrote: ↑25 Sep 2022, 05:39Welcome to this AutoHotkey forum!
Code: Select all
Run, explorer #IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe F3:: file := getSelected().1 SplitPath, file, fn, dir,, fnBare file := dir "\" fnBare "\" fn MsgBox, %file% Return #IfWinActive getSelected() { ; Adapted: https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker hwnd := WinExist("A"), selection := [] WinGetClass, class If (class ~= "(Cabinet|Explore)WClass") For window in ComObjCreate("Shell.Application").Windows If (window.hwnd = hwnd) For item in window.document.SelectedItems selection.Push(item.Path) Return selection }
Artur
Re: Select Folder with exact name
This script is triggered by pressing F3. You can try it to verify that it does what you need.
Last edited by mikeyww on 25 Sep 2022, 08:44, edited 2 times in total.
Re: Select Folder with exact name
It's working fine for me.
Re: Select Folder with exact name
Thank you, BoBo.
For a click:
For a click:
Code: Select all
Run, explorer
#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe
~LButton::
MouseGetPos,,,, control
If Instr(control, "Tree") {
ToolTip
Return
}
file := getSelected().1
SplitPath, file, fn, dir,, fnBare
file := dir "\" fnBare "\" fn
ToolTip, %file%
Return
#IfWinActive
getSelected() {
; Adapted: https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
hwnd := WinExist("A"), selection := []
WinGetClass, class
If (class ~= "(Cabinet|Explore)WClass")
For window in ComObjCreate("Shell.Application").Windows
If (window.hwnd = hwnd)
For item in window.document.SelectedItems
selection.Push(item.Path)
Return selection
}
Re: Select Folder with exact name
I really appreciate your help, not sure why it's not working.
While using the initial script, I get the messagebox but it doesn't add the folder to the selection.
I've attached an example, do you have an idea what that might be?
Thank you,
Artur
While using the initial script, I get the messagebox but it doesn't add the folder to the selection.
I've attached an example, do you have an idea what that might be?
Thank you,
Artur
- Attachments
-
- screen.PNG (39.62 KiB) Viewed 751 times
Re: Select Folder with exact name
Do you mean that the selected file should be moved finally to the folder of the same name?...but it doesn't add the folder to the selection.
Re: Select Folder with exact name Topic is solved
Code: Select all
Run, explorer
#IfWinActive ahk_class CabinetWClass ahk_exe explorer.exe
~*LButton Up::
MouseGetPos,,,, control
If Instr(control, "Tree") {
ToolTip
Return
}
file := getSelected().1
SplitPath, file,, dir,, fnBare
ToolTip, % dir "\" fnBare
For window in ComObjCreate("Shell.Application").Windows
If WinActive() = window.hwnd
Try window.Document.SelectItem(dir "\" fnBare, True)
Return
#IfWinActive
getSelected() {
; Adapted: https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
hwnd := WinExist("A"), selection := []
WinGetClass, class
If (class ~= "(Cabinet|Explore)WClass")
For window in ComObjCreate("Shell.Application").Windows {
Try window.hwnd
Catch
Return
If (window.hwnd = hwnd)
For item in window.document.SelectedItems
selection.Push(item.Path)
}
Return selection
}
Last edited by mikeyww on 25 Sep 2022, 09:20, edited 1 time in total.
Re: Select Folder with exact name
Maybe I did a poor job describing it, sorry. Hope the image helps
When you click a file (or press F3), you should get the folder selected (if there is one with the same name)
When you click a file (or press F3), you should get the folder selected (if there is one with the same name)
- Attachments
-
- screen2.PNG (44.99 KiB) Viewed 725 times
Re: Select Folder with exact name
Thank you mikeyww!!!!!!
That works like a charm!!!
That works like a charm!!!
Re: Select Folder with exact name
OK. I think that my last post (script) works with a click. I also changed the hotkey to have * and Up.
Re: Select Folder with exact name
That's amazing!
This all looks like wizardry to me and I don't know if that's asking too much, but could I ask you for one more feature?
Could it work if I select more than 1 file? In other words - it should always select a corresponding folder when you click on more and more files. So you end up with 2, 4, 6, 8 selected objects, etc.
I have no idea if that's a big effort, but either way, thank you so much for helping me clean years of negligence of my database
Artur
This all looks like wizardry to me and I don't know if that's asking too much, but could I ask you for one more feature?
Could it work if I select more than 1 file? In other words - it should always select a corresponding folder when you click on more and more files. So you end up with 2, 4, 6, 8 selected objects, etc.
I have no idea if that's a big effort, but either way, thank you so much for helping me clean years of negligence of my database
Artur
Re: Select Folder with exact name
That's what my last script does.
Re: Select Folder with exact name
It really does!!! Thank you so much!!
You got the patience of an angel, sorry for being difficult.
Have a wonderful end of the week!
You got the patience of an angel, sorry for being difficult.
Have a wonderful end of the week!