Rename a .jpg file using the name of the containing folder Topic is solved
Rename a .jpg file using the name of the containing folder
Hi,
my first post here..
( From a quick search i cannot find an answer...)
I have over 500 folders.
Each one contains one .jpg and one .psd file
I want to rename only the .jpg inside the folder using the name of the containing folder
It is possible?
my first post here..
( From a quick search i cannot find an answer...)
I have over 500 folders.
Each one contains one .jpg and one .psd file
I want to rename only the .jpg inside the folder using the name of the containing folder
It is possible?
Re: Rename a .jpg file using the name of the containing folder
Welcome to this AutoHotkey forum.
Code: Select all
dir = %A_ScriptDir%\test
SplitPath, dir, name
Loop, Files, %dir%\*.jpg
{ FileMove, %A_LoopFilePath%, %dir%\%name%.jpg
If ErrorLevel
MsgBox, 48, Error, An error occurred while renaming the file.`n`n%A_LoopFilePath%
Break
}
MsgBox, 64, Done, Done!
Return
Re: Rename a .jpg file using the name of the containing folder
Hello, thank you for the welcome and the code!
It is possible to edit your code for every selected folder?
I found a similar code witch works on every selected file
It is possible to edit your code for every selected folder?
I found a similar code witch works on every selected file
Code: Select all
#IfWinActive ahk_class CabinetWClass
^F6:: ;explorer - focused file get path, create folder, copy file
WinGet, hWnd, ID, A
oWin := ""
for oWin2 in ComObjCreate("Shell.Application").Windows
if (oWin2.HWND = hWnd)
{
oWin := oWin2
break
}
oWin2 := ""
if !oWin
return
vPath := oWin.Document.FocusedItem.path
oWin := ""
if !(vAttrib := FileExist(vPath))
|| InStr(vAttrib, "D")
return
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
vDirNew := vDir "\" vNameNoExt
vPathNew := vDirNew "\" vName
FileCreateDir, % vDirNew
;MsgBox, % vPath "`r`n`r`n" vPathNew
;FileCopy, % vPath, % vPathNew
FileMove, % vPath, % vPathNew
return
Re: Rename a .jpg file using the name of the containing folder Topic is solved
Code: Select all
F3::
For each, dir in getSelected() {
If !Instr(FileExist(dir), "D")
Continue
SplitPath, dir, name
Loop, Files, %dir%\*.jpg
{ FileMove, %A_LoopFilePath%, %dir%\%name%.jpg
If ErrorLevel
MsgBox, 48, Error, An error occurred while renaming the file.`n`n%A_LoopFilePath%
Break
}
}
MsgBox, 64, Done, Done!
Return
getSelected() { ; 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: Rename a .jpg file using the name of the containing folder
Thank you for the new code
I don't know if i do something wrong, but although i get the "done" message, the renaming is not done
Please see the screen recording
https://screencast-o-matic.com/watch/c3Vq2FVoLj2
I was expecting the jpg inside the "Test dir" to be renamed as "Test dir.jpg"
I don't know if i do something wrong, but although i get the "done" message, the renaming is not done
Please see the screen recording
https://screencast-o-matic.com/watch/c3Vq2FVoLj2
I was expecting the jpg inside the "Test dir" to be renamed as "Test dir.jpg"
Re: Rename a .jpg file using the name of the containing folder
Ignore my latest reply,
your code works fine everywhere except at Windows desktop!
Thank you!
your code works fine everywhere except at Windows desktop!
Thank you!
Re: Rename a .jpg file using the name of the containing folder
OK. The script is for File Explorer, as you made no prior mention of the desktop. Below is a way to get the desktop selection if you need that.
viewtopic.php?p=154836#p154836
viewtopic.php?p=154836#p154836
Re: Rename a .jpg file using the name of the containing folder
oups,
i posted the question at wrong topic!
Please ignore it!
Hello again!
i can use your help again?
Your code works fine of one selection
Can be edited to work for all selected folders?
i posted the question at wrong topic!
Please ignore it!
Hello again!
i can use your help again?
Your code works fine of one selection
Can be edited to work for all selected folders?
Re: Rename a .jpg file using the name of the containing folder
Hi, the correct question is:
I have found a script to copy selected file name / create a new folder / copy the file to folder
viewtopic.php?f=76&t=60237
Can be adapted to work with all selected files, not one by one?
Thank you!
(I am trying many hours to accomplish it, without success...)
I have found a script to copy selected file name / create a new folder / copy the file to folder
viewtopic.php?f=76&t=60237
Can be adapted to work with all selected files, not one by one?
Thank you!
(I am trying many hours to accomplish it, without success...)
Re: Rename a .jpg file using the name of the containing folder
The script works to rename one file in each selected folder.
Re: Rename a .jpg file using the name of the containing folder
It is possible to work with multiple files selection ?
Re: Rename a .jpg file using the name of the containing folder
Since you want to name the file according to its directory, it would not work for multiple files within a directory, since they would have the same name.
Re: Rename a .jpg file using the name of the containing folder
May be i had to post new topic because my new question is not about "Rename a .jpg file using the name of the containing folder"
It is about the topic viewtopic.php?f=76&t=60237
"copy selected file name / create a new folder / copy the file to folder"
I am asking for:
Select multiple files
For each file
copy selected file name / create folder using this file name / copy the file to created folder
Go to next file
(There isn't same named folders problem)
I hope it s more clear now!
(Sorry for my not so good English, me native language is Greek)
It is about the topic viewtopic.php?f=76&t=60237
"copy selected file name / create a new folder / copy the file to folder"
I am asking for:
Select multiple files
For each file
copy selected file name / create folder using this file name / copy the file to created folder
Go to next file
(There isn't same named folders problem)
I hope it s more clear now!
(Sorry for my not so good English, me native language is Greek)
Re: Rename a .jpg file using the name of the containing folder
If your question does not match this thread's topic, then please put it into a thread where it does match. At least that is my advice. Thank you.
Re: Rename a .jpg file using the name of the containing folder
I will, thank you!