mardi 26 octobre 2021

Incrementing alphabet in batch-file

I want to create a For loop to look if a program is on a flash drive, and copy a text file if it is. Since the drive letter varies on every PC, I want it to look at every drive letter.

if exist "D:\Test.exe" (
    copy "%FileName%.txt" "D:\" >nul
)
if exist "E:\Test.exe" (
    copy "%FileName%.txt" "E:\" >nul
)
if exist "F:\Test.exe" (
    copy "%FileName%.txt" "F:\" >nul
)
if exist "G:\Test.exe" (
    copy "%FileName%.txt" "G:\" >nul
)
Rem ...Continues possibly until drive Z or once it finds the file

Is there a way to create a For loop to increment the drive letter so I don't have to make an If statement each time?

Aucun commentaire:

Enregistrer un commentaire