Reputation: 1219
I need change a lot of folders with a batch script file..
I have those format of name folders:
I need change for this:
Invert the number 12 with the number 03
This is possible using a windows batch file?
Upvotes: 1
Views: 278
Reputation: 10711
Using StringSolver, which requires a valid JRE installation and sbt, allows to use a semi-automatic version of move:
move 2013.03.12.08.05.06_Debug_Test1 2013.12.03.08.05.06_Debug_Test1
Then check the transformation:
move --explain
concatenates for all a>=0 (a 2-digit number from the substring starting at the a+1-th number ending at the end of the a+1-th AlphaNumeric token in first input + the substring starting at the 2*a+2-th token not containing 0-9a-zA-Z ending at the end of the a+3-th non-number in first input) + the first input starting at the 4th AlphaNumeric token.
which means that it decomposed the transformation by:
2013.12.03.08.05.06_Debug_Test1
AAAABBBBAABCCCCCCCCCCCCCCCCCCCC
where
A is "a 2-digit number from the substring starting at the a+1-th number ending at the end of the a+1-th AlphaNumeric token in first input"
B is "the substring starting at the 2*a+2-th token not containing 0-9a-zA-Z ending at the end of the a+3-th non-number in first input"
C is "the first input starting at the 4th AlphaNumeric token."
which corresponds to what you expected for folders of this type.
If you do not trust it, you can have a dry run:
move --test
which displays what the mapping would do on all folders.
Then perform the transformation for all folders using move --auto
or the abbreviated command
move
Using the Monitor.ps1
modified and run in Powershell -Sta
, you can do it yourself in Windows like in this Youtube video.
DISCLAIMER: I am a co-author of this software developped for academic purposes.
Upvotes: 1
Reputation: 80193
@echo off
for /f "tokens=1,2,3*delims=." %%a in ('dir /b /ad "*.*.*.*") do if not %%b==%%c echo ren "%%a.%%b.%%c.%%d" "%%a-%%c.%%b.%%d"
for /f "tokens=1,2,3*delims=.-" %%a in ('dir /b /ad "*-*.*.*") do if not %%b==%%c echo ren "%%a-%%b.%%c.%%d" "%%a.%%b.%%c.%%d"
Should get you started.
The first FOR
selects directories of the format *.*.*.*
and renames them *-*.*.*
with the 2nd and 3rd elements swapped.
The second renames the renamed directories to change the -
to .
Consider directories 2013.03.12.08.05.06_Debug_Test1
and 2013.12.03.08.05.06_Debug_Test1
- attempting to rename the one will fail because the other exists, hence need to rename twice.
(I've assumed that '-' does not exist in your directorynames - you may wish to substitute some other character - #
,@
,$
,q
suggest themselves)
Note that I've simply ECHO
ed the rename. Since the second rename depends on the first, the second set wouldn't be produced until the echo
is removed from the first after careful checking.
I'd suggest you create a sample subdirectory to test first, including such names as I've highlighted.
Upvotes: 4