Page 2 of 2

Re: If one of two files exist then do something.

Posted: 07 Oct 2019 13:43
by aGerman
That's weird. Right now I tried the code. Works nicely for me.

Steffen

Re: If one of two files exist then do something.

Posted: 07 Oct 2019 14:07
by PAB
Sorry, it was my fault!

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"
)
Took them out and it works perfectly!

Re: If one of two files exist then do something.

Posted: 25 Oct 2019 20:55
by CJM
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.

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
Instead of GOTO, CALL or SET could be used to instead check every file, or using the bit method previously mentioned.

Re: If one of two files exist then do something.

Posted: 27 Oct 2019 05:37
by PAB
Thanks for the input CJM, it is very much appreciated!