0

I want to check if a file exists in a path and then if it exists do a loop. e.g.

IF EXIST "C:\FILE" THEN
LOOP CONDITION
END IF 

but in .cmd programming. How would it look like?

dbenham
  • 127,446
  • 28
  • 251
  • 390
Rory Lester
  • 2,858
  • 11
  • 49
  • 66

2 Answers2

0

The syntax is like this:

IF EXIST filename. (
FOR %%A IN (1 2 3) DO GOTO=%%A
    :1
    ECHO 1
    GOTO End
    :2
    ECHO 2
    GOTO End
    :3
    ECHO 3
    :End
) ELSE (
echo filename. missing.
)

Take a look at this

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
  • Thank you. I do have a further question, where it says 'filename.' do i add the path in quotes? e.g. IF EXISTS "C:\FILENAME".( – Rory Lester Feb 26 '13 at 07:14
0

I assume that you are using Visual Basic (at least the syntax of IF statement is showing it), if yes, then use FileInfo object like Dim fi As New FileInfo("C:\File.txt") IF fi.Exists() THEN ' Do your loop here END IF

Usman Waheed
  • 555
  • 5
  • 14