Could any of you help me with a problem I have with a lot of files with the same name, placed in sperate folders.
The folders are named with numbers, but the files
@ECHO OFF
SETLOCAL enabledelayedexpansion
SET startfrom=c:\sourcedir
SET destdir=c:\destdir
FOR /f "delims=" %%i IN ('dir /s /b "%startfrom%\index.*"') DO (
FOR %%e IN (jpg html pdf) DO IF /i .%%e==%%~xi (
FOR %%d IN ("%%~dpi.") DO (
SET "var=%%~nxd"
IF "!var:~6!"=="" (
SET "var="
SET /a var=1%%~nxd 2>NUL
IF DEFINED var IF !var! geq 1000000 IF !var! leq 1999999 (
ECHO MOVE "%%i" "%destdir%\%%~nxd%%~xi"
)
)
)
)
)
set
a variable to 1000000..1999999 if 6-digit nameECHO
the move command (remove ECHO keyword to perform move)Annotated test structure:
c:\sourcedir\index.pdf not 6-digit dir
c:\sourcedir\000000\index.jpg
c:\sourcedir\000009\index.css extension not specified
c:\sourcedir\000009\index.html
c:\sourcedir\000009\index.jpg
c:\sourcedir\000009\index.pdf
c:\sourcedir\000009\index.txt extension not specified
c:\sourcedir\010+39\index.txt not 6-digit dir
c:\sourcedir\12345\index.jpg not 6-digit dir
c:\sourcedir\1234567\index.jpg not 6-digit dir
c:\sourcedir\123x56\index.jpg
c:\sourcedir\50000-0000\index.jpg not 6-digit dir
c:\sourcedir\5000000000\index.jpg not 6-digit dir
c:\sourcedir\999-99\index.jpg not 6-digit dir
c:\sourcedir\999999\index.jpg
c:\sourcedir\a\index.jpg not 6-digit dir
c:\sourcedir\yellow\index.jpg not 6-digit dir
Results:
MOVE "c:\sourcedir\000000\index.jpg" "c:\destdir\000000.jpg"
MOVE "c:\sourcedir\000009\index.html" "c:\destdir\000009.html"
MOVE "c:\sourcedir\000009\index.jpg" "c:\destdir\000009.jpg"
MOVE "c:\sourcedir\000009\index.pdf" "c:\destdir\000009.pdf"
MOVE "c:\sourcedir\999999\index.jpg" "c:\destdir\999999.jpg"