I have a lot of files in subdirectories, which i want to have
- in one folder without subdirectories
- renamed with the uppermost directory as prefix followed by its genuine file name.
E.g.:
dir1\dir2\dir3\fileA.abc --> Output\dir1-fileA.abc
dir4\dir5\fileB.def --> Output\dir4-fileB.def
I tried to adapt the solution given in Batch file to copy and rename files from multiple directories for my purposes with the following code, but it is getting stuck in an endless loop as it seems.
Any ideas how to fix this?
pushd "C:\SomeDirectory"
if not exist "Output\*" md Output
for /D %%D in (*) do (
if /I not "%%D" == "Output" (
for /R %%J in ("*.*") do (
copy /B /Y "%%~fJ" "Output\%%D-%%~nxJ" >nul
)
)
)
pause