I have three or more directories with subdirectories in which I have to check and sort thousands of files named "00001_*.jpg"
to "99999_*.jpg"
.
But for the sake of keeping it simple, we will test a sample of 20 images.
For example I have three parent directories A
, B
and C
. Inside of directory B
are four images 00017_0.jpg
, 00018_0.jpg
, 00019_0.jpg
and 00020_0.jpg
. I would like to run a script which detects those filenames e.g. in directory A
and move them into a subdirectory named Check
, (ACheck
).
I have tried to store filenames into an array, but I am already stuck. I tried to store them into list_1
, but when I echo
the result I get nothing ""
.
I edit the path to the images in directory B
in FolderPath
using parameters: default
, default
, 20
Resulting in:
Start value (default: 1):
Increment by: (default: 1):
Last value (default: 99999): 20
Not exist: 00001_0.jpg
Not exist: 00002_0.jpg
Not exist: 00003_0.jpg
Not exist: 00004_0.jpg
Not exist: 00005_0.jpg
Not exist: 00006_0.jpg
Not exist: 00007_0.jpg
Not exist: 00008_0.jpg
Not exist: 00009_0.jpg
Not exist: 00010_0.jpg
Not exist: 00011_0.jpg
Not exist: 00012_0.jpg
Not exist: 00013_0.jpg
Not exist: 00014_0.jpg
Not exist: 00015_0.jpg
Not exist: 00016_0.jpg
Found file: 00017_0.jpg
Found file: 00018_0.jpg
Found file: 00019_0.jpg
Found file: 00020_0.jpg
"The length of the array is" 0
Press any key to continue . . .
Below is my adaption of this script.
It found the files in directory B
, but my additions regarding list_1
array have not worked out, so I am unable to move them the Check
subdirectory; (this part is not yet scripted).
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "list_1="
set "ValueStart=1"
set "ValueIncrement=1"
set "ValueLast=99999"
set /P "ValueStart=Start value (default: %ValueStart%): "
set /P "ValueIncrement=Increment by: (default: %ValueIncrement%): "
set /P "ValueLast=Last value (default: %ValueLast%): "
set "FolderPath=%USERPROFILE%foldersubfolder"
setlocal EnableDelayedExpansion
for /L %%G in (%ValueStart%,%ValueIncrement%,%ValueLast%) do (
if %%G LSS 100000 (
set "FileName=0000%%G"
set "FileName=!FileName:~-5!_0.jpg"
) else set "FileName=%%G_0.jpg"
if exist "!FolderPath!!FileName!" (
set "list_1[%%G]=FileName"
echo Found file: !FileName!) else echo Not exist: !FileName!
)
set "x=0"
:SymLoop
if defined list_1[%x%] (
call echo %%list_1[%x%]%%
set /a "x+=1"
GOTO :SymLoop
)
echo "The length of the array is" %x%
pause
endlocal
16
It will save me years of time. I don’t need an array to move files but arrays were important to me as they offered a structure I am able to scale. Moves and many other tasks can now be automated from arrays. Expanding the script below can move the images that need to be checked. Which is one of many manually laborious Windows tasks that I never have to do again 🙂 …
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "List_1="
set "ValueStart=0"
set "ValueIncrement=1"
set "ValueLast=99999"
set /P "ValueStart=Start value (default: %ValueStart%): "
set /P "ValueIncrement=Increment by: (default: %ValueIncrement%): "
set /P "ValueLast=Last value (default: %ValueLast%): "
set "FolderPath=%USERPROFILE%foldersubfolder"
setlocal EnableDelayedExpansion
for /L %%G in (%ValueStart%,%ValueIncrement%,%ValueLast%) do (
if %%G LSS 100000 (
set "FileName=0000%%G"
set "FileName=!FileName:~-5!_0.jpg"
) else set "FileName=%%G_0.jpg"
if exist "!FolderPath!!FileName!" (
set "List_1[%%G]=!FileName!"
set List_1[%%G]=!list_1[%%G]!
echo Found file: !FileName!
) else (
set List_1[%%G]=""
echo Not exist: !FileName!
)
echo List_1[%%G]=!List_1[%%G]!
)
pause
endlocal
Results in
Start value (default: 0):
Increment by: (default: 1):
Last value (default: 99999): 20
Not exist: 00000_0.jpg
List_1[0]=""
Not exist: 00001_0.jpg
List_1[1]=""
Not exist: 00002_0.jpg
List_1[2]=""
Not exist: 00003_0.jpg
List_1[3]=""
Not exist: 00004_0.jpg
List_1[4]=""
Not exist: 00005_0.jpg
List_1[5]=""
Not exist: 00006_0.jpg
List_1[6]=""
Not exist: 00007_0.jpg
List_1[7]=""
Not exist: 00008_0.jpg
List_1[8]=""
Not exist: 00009_0.jpg
List_1[9]=""
Not exist: 00010_0.jpg
List_1[10]=""
Not exist: 00011_0.jpg
List_1[11]=""
Not exist: 00012_0.jpg
List_1[12]=""
Not exist: 00013_0.jpg
List_1[13]=""
Not exist: 00014_0.jpg
List_1[14]=""
Not exist: 00015_0.jpg
List_1[15]=""
Not exist: 00016_0.jpg
List_1[16]=""
Found file: 00017_0.jpg
List_1[17]=00017_0.jpg
Found file: 00018_0.jpg
List_1[18]=00018_0.jpg
Found file: 00019_0.jpg
List_1[19]=00019_0.jpg
Found file: 00020_0.jpg
List_1[20]=00020_0.jpg
Press any key to continue . . .