if statement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
daillest319
Posts: 27
Joined: 31 Jan 2012 14:45

if statement

#1 Post by daillest319 » 21 Jun 2012 07:44

very new to batch script and i was wondering how i can do a if statement. I'm trying to automate to copy a .txt file and if it exist and paste it in a folder....i want to copy the file and paste to new folder and then go on to the next step which is just starting a .exe. and if it doesn't exist i want the batch script to quit and not continue to the next line.

Code: Select all

@echo off
copy /y "C:\Test\test.txt" "C:\NewFolder\"
PING 1.1.1.1 -n 1 -w 2000 >NUL
start /d "C:\NewFolder\" Progam.exe

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

Re: if statement

#2 Post by Squashman » 21 Jun 2012 07:52

Code: Select all

@echo off

IF EXIST "C:\Test\test.txt" (
     copy /y "C:\Test\test.txt" "C:\NewFolder\"
     PING 1.1.1.1 -n 1 -w 2000 >NUL
     start /d "C:\NewFolder\" Progam.exe
     ) else (
     GOTO :EOF
)

daillest319
Posts: 27
Joined: 31 Jan 2012 14:45

Re: if statement

#3 Post by daillest319 » 21 Jun 2012 08:19

Thank you so much worked perfect. i just have one question what is GOTO :EOF

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: if statement

#4 Post by Ed Dyreen » 21 Jun 2012 08:30

'
EOF may refer to:

End-of-file, the computing term for an end-of-file condition or its tangible indication
Enterprise Objects Framework, a product from Apple Computer :lol:

http://en.wikipedia.org/wiki/End-of-file
In computing, end of file (commonly abbreviated EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

Post Reply