I require a windows batch script to recursively rename files and folders with the name of the parent folder and add a prefix/suffix.
I have 2 folders fol1
and fol2
, with the following directory structure:
fol1
├───fol1.1
│ └───text.txt
├───fol1.2
│ └───text.txt
fol2
├───fol2.1
└───fol2.2
I want the tree renamed as:
lon_fol1_par
├───lon_fol1.1_par
│ └───fol1.1_text.txt
├───lon_fol1.2_par
│ └───fol1.2_text.txt
lon_fol2_par
├───lon_fol2.1_par
└───lon_fol2.2_par
The code that helped me renaming is as follows:
FOR /F "tokens=1 delims=" %%A IN ('DIR /B /S /A:D') DO (
FOR /F "tokens=1 delims=" %%B IN ('DIR /B /A:-D "%%A"') DO (
pushd %%A
FOR %%I IN (.) DO RENAME "%%A\%%B" "<Name I want>"%%~xB
popd ..
)
)