File requirement checks as one liner?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
noprogrammer
Posts: 36
Joined: 29 Oct 2009 11:55

File requirement checks as one liner?

#1 Post by noprogrammer » 12 Oct 2016 07:12

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?

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: File requirement checks as one liner?

#2 Post by Squashman » 12 Oct 2016 07:28

Just use a normal FOR command. You don't need the /F.

noprogrammer
Posts: 36
Joined: 29 Oct 2009 11:55

Re: File requirement checks as one liner?

#3 Post by noprogrammer » 30 Nov 2016 08:13

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...

Post Reply