That's weird. Right now I tried the code. Works nicely for me.
Steffen
[SOLVED] If one of two files exist then do something.
Moderator: DosItHelp
Re: If one of two files exist then do something.
Sorry, it was my fault!
I added the userprofile%\Desktop\ to the beginning of "File1.exe" "File2.exe" "File3.exe"
Took them out and it works perfectly!
I added the userprofile%\Desktop\ to the beginning of "File1.exe" "File2.exe" "File3.exe"
Code: Select all
for %%f in ("File1.exe" "File2.exe" "File3.exe") do (
if exist "%userprofile%\Desktop\%%~f" set /A "bitset|=bit"
set /A "bit<<=1"
)
Re: If one of two files exist then do something.
The FOR command is perfect for this, and I'm a big fan of testing the presence of any attributes (using %%~a) to determine if a file exists. By doing this in a subsequent FOR ... IN (), lack of file attributes will result in a (null) FOR set and will not GOTO, so if any of the files in the original FOR list are present, the GOTO will exit further checking.
Instead of GOTO, CALL or SET could be used to instead check every file, or using the bit method previously mentioned.
Code: Select all
@For %%F in (
File1.txt
Fil2.exe
Filehere.dat
) do @For %%f in (%%~aF) do GOTO :Exist
ECHO=No files found
GOTO:EOF
:Exist
Re: If one of two files exist then do something.
Thanks for the input CJM, it is very much appreciated!