I'm currently trying to rename a file in a subfolder appending both the his subfolders name, the subfolder name immediately above in the path, and current date. This is the full path:
C:\USER_VALIDATION\INPUT\GRUPPO_FARLOCCO\AIX\merge.csv
I'd like that merge.csv become GRUPPO_FARLOCCO_AIX_17072020.csv I need to do that in a batch file and in a FOR, because I need to repeat this renaming action in every subfolder
C:\USER_VALIDATION\INPUT\.
Up until now I can get to this result: AIX_17072020.csv
with the following code
FOR /D /R %%# in (*) DO (
PUSHD "%%#"
FOR %%@ in ("merge*") DO (
Echo Ren: ".\%%~n#\%%@" "%%~n#_%date:/=%%%~x@"
Ren "%%@" "%%~n#_%date:/=%%%~x@"
)
POPD
)
Pause&Exit
Now, I can get \USER_VALIDATION\INPUT\GRUPPO_FARLOCCO\AIX\
with %%~p@
but I cannot just get only the last two folders. I think it could be effective just remove the first 23 characters and replace the remaining two "" with "_" but I can't do it.
Can someone please help?
Thank you!