hi all,
I am trying to write a script that does this:
1- I navigate to a folder
2- I right click in that folder and click "rename all"
3- script reads the folder name and grabs the folder name only (eg C:\user\name\currfolder in this case 'currfolder')
4- rename all files within this folder as below:
file_1.pdf -> file_1.currfolder.pdf
file_2.pdf -> file_2.currfolder.pdf
.
.
file_n.pdf to file_n.currfolder.pdf
appreciate some guidelines or if anyone aware of a similar script which I may be able to modify and use.
append file names with the current folder names
Re: append file names with the current folder names
Code: Select all
#SingleInstance, Force
#Persistent
fExt := "ahk" ; change accordingly
fPath := A_ScriptDir ; change accordingly
F10:: ; press F10 to start renaming files
Loop, Files,% fPath . "\*." fExt
{
SplitPath, A_LoopFileFullPath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
fDir := StrSplit(OutDir,"\")
FileMove,% A_LoopFileFullPath,% OutNameNoExt "_" . fDir[fDir.MaxIndex()] . "." . OutExtension, 0 ; specify a different destination path to move instead of renaming files
}
Return
Re: append file names with the current folder names
Thanks Bobo,
The A_ScriptDir in this context returns the path of the ahk script and not the folder I am in. I am trying to find a way to extract the current folder path based on "mouse right click' event.
The A_ScriptDir in this context returns the path of the ahk script and not the folder I am in. I am trying to find a way to extract the current folder path based on "mouse right click' event.
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: append file names with the current folder names
nicrox, if you need to get the title and path of an active folder, you may use this:
Code: Select all
$F10::
title := GetShellFolder().Title
folderPath := GetShellFolder().Self.Path
MsgBox, % title . "`n" . folderPath
return
GetShellFolder(hwnd := "")
{
( !hwnd && hwnd := WinExist("A") )
WinGet, process, ProcessName, ahk_id %hwnd%
WinGetClass, winClass, ahk_id %hwnd%
if !( process = "explorer.exe" && winClass ~= "(Cabinet|Explore)WClass" )
Return
for window in ComObjCreate("Shell.Application").Windows
if ( window.hwnd = DllCall("GetAncestor", Ptr, hwnd, "UInt", GA_ROOT := 2, Ptr) )
return window.document.Folder
}
Who is online
Users browsing this forum: wilkster and 311 guests