So my dad has tons of music and wants to rename them.
i want the code to remove sections of a name, like
remove "- TSM" completely (spaces included)
I really dont know how i should set this up, ive found code on editing Filenames,
but i would really like a seperate txt file for text to remove,
for future use maybe.
Im really lost here, sorry.
What i mean is have a Textdocument set up like this:
"- TSM"
"- KaraO"
a function to edit "- TSM" to something else would be great too
So maybe a txt called "edit.txt" and "remove.txt" would be in the same DIR as the Script.
Thanks a lot!
Renaming Files using txt-template Topic is solved
Re: Renaming Files using txt-template Topic is solved
Code: Select all
music = %A_ScriptDir%\music ; Music directory
subs = %music%\subs.txt ; Substitutions
If !FileExist(subs) {
MsgBox, 48, Error, Substitution file not found. Aborting.
Return
} Else FileRead, subsText, %subs%
sub := StrSplit(subsText, "`r`n") ; Put the sub lines into an array
Loop, Files, %music%\*.mp3, R ; Loop through MP3 files
{ fn := A_LoopFileName
For each, line in sub
part := StrSplit(line, "|"), fn := StrReplace(fn, part.1, part.2)
If (fn = A_LoopFileName) ; If name has not changed,
Continue ; continue to the next iteration;
FileMove, %A_LoopFilePath%, %A_LoopFileDir%\%fn% ; otherwise, rename the file
If ErrorLevel
MsgBox, 48, Error, An error occurred while renaming the file.`n`n%A_LoopFilePath%
}
MsgBox, 64, Success, Done!
- Attachments
-
- subs.txt
- (19 Bytes) Downloaded 21 times
-
- Posts: 2
- Joined: 18 Oct 2021, 12:18
Re: Renaming Files using txt-template
Okay so would it be able to domikeyww wrote: ↑18 Oct 2021, 15:50Code: Select all
music = %A_ScriptDir%\music ; Music directory subs = %music%\subs.txt ; Substitutions If !FileExist(subs) { MsgBox, 48, Error, Substitution file not found. Aborting. Return } Else FileRead, subsText, %subs% sub := StrSplit(subsText, "`r`n") ; Put the sub lines into an array Loop, Files, %music%\*.mp3, R ; Loop through MP3 files { fn := A_LoopFileName For each, line in sub part := StrSplit(line, "|"), fn := StrReplace(fn, part.1, part.2) If (fn = A_LoopFileName) ; If name has not changed, Continue ; continue to the next iteration; FileMove, %A_LoopFilePath%, %A_LoopFileDir%\%fn% ; otherwise, rename the file If ErrorLevel MsgBox, 48, Error, An error occurred while renaming the file.`n`n%A_LoopFilePath% } MsgBox, 64, Success, Done!
Loop, Files, %music%\*.*, R
because there arent just mp3 files in there..?