Renaming multiple files using batch file
Verfasst: Mi 1. Feb 2012, 12:38
Hi guys,
I'm working on a batch file for quite a while now but I can't solve a problem.
I'm working on a Windows Vista system and I created a *.cmd file using the Windows Editor.
Description of my task:
Within the script I ask the user to input several variables, i.e. "VORJAHR" (i.e. 2011), "VORMONAT" (i.e. 12), "JAHR" (i.e. (2012). "MONAT" (i.e. 01).
I do then take those variables to search for files in several folders and subfolders (which is the variable "VORLAGENORDNER") having used "VORJAHR_VORMONAT" within their filenames. The filenames are structured either ABCDEFG_2011_12.doc or ABCDEFG_2011_12_en.doc, while "ABCDEFG" is not defined in length or structure.
Now, I want to replace the variables "VORJAHR_VORMONAT" (i.e. 2011_12) with "JAHR_MONAT" (i.e. 2012_01).
In other words the target files should be renamed from ABCDEFG_2011_12.doc to ABCDEFG_2012_01.doc.
My command line so far:
forfiles /p %VORLAGENORDNER% /m *%VORJAHR_VORMONAT%* /s /C "cmd /c ren @file *%JAHR_MONAT%*"
What do I do wrong?
I hope that someone can help me on that account.
Thanks in advance!
fibre
I'm working on a batch file for quite a while now but I can't solve a problem.
I'm working on a Windows Vista system and I created a *.cmd file using the Windows Editor.
Description of my task:
Within the script I ask the user to input several variables, i.e. "VORJAHR" (i.e. 2011), "VORMONAT" (i.e. 12), "JAHR" (i.e. (2012). "MONAT" (i.e. 01).
I do then take those variables to search for files in several folders and subfolders (which is the variable "VORLAGENORDNER") having used "VORJAHR_VORMONAT" within their filenames. The filenames are structured either ABCDEFG_2011_12.doc or ABCDEFG_2011_12_en.doc, while "ABCDEFG" is not defined in length or structure.
Now, I want to replace the variables "VORJAHR_VORMONAT" (i.e. 2011_12) with "JAHR_MONAT" (i.e. 2012_01).
In other words the target files should be renamed from ABCDEFG_2011_12.doc to ABCDEFG_2012_01.doc.
My command line so far:
forfiles /p %VORLAGENORDNER% /m *%VORJAHR_VORMONAT%* /s /C "cmd /c ren @file *%JAHR_MONAT%*"
What do I do wrong?
I hope that someone can help me on that account.
Thanks in advance!
fibre