a question about the IF DOS command

  • Thread starter Thread starter Tim.T
  • Start date Start date
T

Tim.T

I don't know much DOS, but I'm just wondering if it's possible to use IF to
carry out the following:

"IF MyFile.txt does not exist in X directory, create MyFile.txt in (same)
directory"

I get the impression, though, that IF has no "create" or "make" commands
associated with it.

Any help greatly appreciated.

Tim
 
Tim.T said:
I don't know much DOS, but I'm just wondering if it's possible to use IF to
carry out the following:

"IF MyFile.txt does not exist in X directory, create MyFile.txt in (same)
directory"

I get the impression, though, that IF has no "create" or "make" commands
associated with it.

Any help greatly appreciated.

Tim

To understand how to use the IF command, run CMD. From the
prompt, type IF /?, and enter. A list should appear giving
all of the options and the syntax to use. In this case, if
the filename does not exist, then a command instruction, to
create the file follows. (Too tired to work out an example
and the Windows GUI has turned my brain to goo.)
 
Tim.T said:
I don't know much DOS, but I'm just wondering if it's possible to use IF to
carry out the following:

"IF MyFile.txt does not exist in X directory, create MyFile.txt in (same)
directory"

I get the impression, though, that IF has no "create" or "make" commands
associated with it.

Any help greatly appreciated.

Tim

"if" does not need any "create" or "make" commands associated
with it - it is decision maker, nothing more, nothing less. You can
put anything you like after the "if" construct!

if exist "c:\SomeFolder\Tim.txt" echo File not found!
if exist "c:\SomeFolder\Tim.txt" copy /c c:\Tim.txt c:\someFolder
if not exist "c:\SomeFolder\Tim.txt" shutdown.exe /L /R
 
Back
Top