Page 1 of 1

File requirement checks as one liner?

Posted: 12 Oct 2016 07:12
by noprogrammer
Hi,

I'm revising a script, looking for simplifications. The script needs three files to process.
This is what its author originally wrote:

Code: Select all

If Not Exist 7z.dll   Echo 7z.dll missing   &Goto :EOF
If Not Exist 7zFM.exe Echo 7zFM.exe missing &Goto :EOF
If Not Exist 7zG.exe  Echo 7zG.exe missing  &Goto :EOF

So it's the same type of instruction just repeated and I thought of merging this into a one liner if possible.
Basically, what I'd like to achieve is: Check if file0 ... file2 all exist and continue if these files are present.
Otherwise the script should exit with a message (Required file missing).

This

Code: Select all

For /f %%f In (7z.dll 7zFM.exe 7zG.exe) Do (If Not Exist %%~f Echo Missing file, exiting...)
will output StdErr, i.e. the first missing file name but not my defined message.
How would you proceed?

Re: File requirement checks as one liner?

Posted: 12 Oct 2016 07:28
by Squashman
Just use a normal FOR command. You don't need the /F.

Re: File requirement checks as one liner?

Posted: 30 Nov 2016 08:13
by noprogrammer
Sorry for the late reply, of course you were right.
Initially I wanted to do add parameter expansion as well, thus the remnant /f option...