PC Review


Reply
Thread Tools Rate Thread

command prompt : test if file exists?

 
 
loial
Guest
Posts: n/a
 
      9th Aug 2006
Is there a command I can use to test whether a file exists, e.g,
equivelent to the unix "test" command?

 
Reply With Quote
 
 
 
 
Bob I
Guest
Posts: n/a
 
      9th Aug 2006
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?
>


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      9th Aug 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
> >

>



 
Reply With Quote
 
Bob I
Guest
Posts: n/a
 
      9th Aug 2006
Thank you for the correction.

Pegasus (MVP) wrote:

> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>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?
>>>

>>

>
>


 
Reply With Quote
 
3c273
Guest
Posts: n/a
 
      9th Aug 2006
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

"loial" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a command I can use to test whether a file exists, e.g,
> equivelent to the unix "test" command?
>



 
Reply With Quote
 
3c273
Guest
Posts: n/a
 
      9th Aug 2006
You could also go here http://unxutils.sourceforge.net/ , and get GNU
Utilities for Win32, which includes test.exe.
Louis

"loial" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a command I can use to test whether a file exists, e.g,
> equivelent to the unix "test" command?
>



 
Reply With Quote
 
=?Utf-8?B?S2lyYW4gS3VtYXI=?=
Guest
Posts: n/a
 
      11th Aug 2006
Hi,
You could also type "dir/s filename" at the root drive to check. The most
easiest i can think of.

Regards
kiran

--
All is well when u''''r mind is well


"3c273" wrote:

> You could also go here http://unxutils.sourceforge.net/ , and get GNU
> Utilities for Win32, which includes test.exe.
> Louis
>
> "loial" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Is there a command I can use to test whether a file exists, e.g,
> > equivelent to the unix "test" command?
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test if file exists Daniel Bonallack Microsoft Excel Misc 2 4th May 2009 04:19 PM
How to programmatically test whether VBA code exists in an Excel file Paul Martin Microsoft Excel Programming 8 2nd Aug 2006 03:05 AM
If syntax to test if command button exists mikeburg Microsoft Excel Programming 1 30th Sep 2005 01:48 AM
How can u test too see if a file exists in VBA? dee Microsoft Access Reports 2 8th Feb 2005 06:00 PM
Re: test page failed to print --- file already exists. Cari \(MS-MVP\) Windows XP Print / Fax 0 10th Aug 2003 11:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:59 PM.