command prompt : test if file exists?

  • Thread starter Thread starter loial
  • Start date Start date
L

loial

Is there a command I can use to test whether a file exists, e.g,
equivelent to the unix "test" command?
 
Yes, the "If" command


If Performs conditional processing in batch programs.

Syntax
if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist FileName command [else expression]

If command extensions are enabled, use the following syntax:

if [/i] string1 CompareOp string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]
 
This needs some syntax adjustment. The line

if [not] errorlevel number command [else expression]

won't work whereas this line will:

if [not] errorlevel number (command) [else (expression)]

In other words, the ellipses are compulsory when using "else".
Type if /? at the Command Prompt for the full syntax. It says
there specifically:
=================
The following would NOT work because the del command
needs to be terminated by a newline:

IF EXIST filename. del filename. ELSE echo filename. missing
=================
Bob I said:
Yes, the "If" command


If Performs conditional processing in batch programs.

Syntax
if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist FileName command [else expression]

If command extensions are enabled, use the following syntax:

if [/i] string1 CompareOp string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]


Is there a command I can use to test whether a file exists, e.g,
equivelent to the unix "test" command?
 
Thank you for the correction.
This needs some syntax adjustment. The line

if [not] errorlevel number command [else expression]

won't work whereas this line will:

if [not] errorlevel number (command) [else (expression)]

In other words, the ellipses are compulsory when using "else".
Type if /? at the Command Prompt for the full syntax. It says
there specifically:
=================
The following would NOT work because the del command
needs to be terminated by a newline:

IF EXIST filename. del filename. ELSE echo filename. missing
=================
Yes, the "If" command


If Performs conditional processing in batch programs.

Syntax
if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist FileName command [else expression]

If command extensions are enabled, use the following syntax:

if [/i] string1 CompareOp string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]



loial wrote:

Is there a command I can use to test whether a file exists, e.g,
equivelent to the unix "test" command?
 
Use "dir c:\path\file.ext". If the file doesn't exist, it will tell you.. If
it does, you will get the file stats.
Louis
 
Hi,
You could also type "dir/s filename" at the root drive to check. The most
easiest i can think of.

Regards
kiran
 
Back
Top