I need some help to automate rename files in a current directory. The following files that can exits in the directory is for example:
AAA111A.txt
AAA111A.pdf
AAA111A.jpg
BBB222B.jpg
BBB222B.pdf
Where the bold letter stand for the revision of the file. What I want is a PowerShell or batch file where it automatically looks what revision letter it is and then increment that revision letter with the next in the alphabet for all files.
Example:
AAA111A.txt -> AAA111B.txt
BBB222B.pdf -> BBB222C.pdf
etc
The letters and numbers before the revision letter and the extension of the file can vary, so used as a wildcard? It is also possible that the file is named like: AAA111A-01.pdf or AAA111A-blabla.pdf
Hopefully someone can make my life easier for this noobie :).
Thank you in advance!
Building off of Abraham's answer, because the use of a scriptblock with parameter to evaluate the replacement is great and not something I knew about before today. I'd just setup a hashtable ahead of time for the replacement letter(s). I'd replace
zwithaato avoid conflicts, assuming that doesn't break the naming convention.Once you get that setup you can basically do what Abraham suggested, just referencing the hashtable to get the replacement string.
This has the same failing that Abraham's answer does in that it does not check for file name availability before trying to rename a file. It does solve the case where a file's revision is at
Zthough. My regex is also a little more flexible for cases where a file is named something like 'AAAA111C-glarb.txt' and will correctly increment it to 'AAAA111D-glarb.txt'.