Vous pouvez utiliser IF EXIST pour vérifier l'existence d'un fichier :
IF EXIST "filename" (
REM Do one thing
) ELSE (
REM Do another thing
)
Si vous n'avez pas besoin d'un "else", vous pouvez faire quelque chose comme ceci :
set __myVariable=
IF EXIST "C:\folder with space\myfile.txt" set __myVariable=C:\folder with space\myfile.txt
IF EXIST "C:\some other folder with space\myfile.txt" set __myVariable=C:\some other folder with space\myfile.txt
set __myVariable=
Voici un exemple fonctionnel de recherche d'un fichier ou d'un dossier :
REM setup
echo "some text" > filename
mkdir "foldername"
REM finds file
REM "The ELS