Jump to content

If Statements in a script


Recommended Posts

Okay got it, your file must have had a space in the name - sorry my fault.

Copy & paste this into the batch file instead:

@echo off
set SRCDIR=f:\test1
set DSTDIR=f:\test2

for /f "delims=" %%a in ('dir /b "%SRCDIR%"') do (
if not exist "%DSTDIR%\%%a" echo Copying %%a
if not exist "%DSTDIR%\%%a" copy "%SRCDIR%\%%a" "%DSTDIR%" > nul
)

This stops a space being a valid token delimiter and screwing up filenames.

Link to comment
Share on other sites


This VBS script check for TFile, this would be the Path and File name varible. If The Tfile is found it has a message box that popups up

and confirms the Tfile it will then start the copy of the file. If it not there then it will popup a error message.

This is a Simple If Exists Statement

Const OverWriteExisting = True

Dim Fso ,TFile

Set Fso = Createobject("Scripting.FileSystemObject")

TFile = "YOUR_PATH_AND_FILE_NAME_HERE"

If Fso.FileExists(TFile) Then

msgbox "Confirm The File Was Found", 0 + 32,"Found The File"

Fso.Copy(TFile),("YOUR_NEW_LOCATION"),OverWriteExisting

Else

msgbox "Cannot Find The File", 0 + 32,"Can Not Fine File"

End If

Link to comment
Share on other sites

Fantastic!! you are the king of batch files!

were did you learn such intricate knowledge of them? any paticular book? or just years of experience?

thanks ever so much :thumbup:thumbup

Experience.

If you have a need, such as you did, then it pays to be inquisitive - and back when I started playing with PCs you only had DOS.

Some things are just so much easier with a simple batch file than relying on tools, GUIs or scripting engines.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...