Using batch to check if files exist, store filenames into an array and move them

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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 . . .
</code>
<code>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 . . . </code>
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).

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@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
</code>
<code>@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 </code>
@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 🙂 …

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@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
</code>
<code>@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 </code>
@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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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 . . .
</code>
<code>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 . . . </code>
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 . . .

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật