paulhaley
asked on
Creating a Batch Script that will not copy if file exists
Hi All
I need to write a script that will be a scheduled job, part of this needs to be if a file exists it will not mov the new file into the area concerned, if it does not exist it will copy it, does a what if command exist in DOS,
the OS is is Windows 2000 Server and i am writing a batch file that will FTP a file down then transfer the file to another area for processing , this file name will always be the same, so if the previous one is still there the new one cannot go into the folder, the new file has to wait until this one has been processed
Thank you all in anticipation
I need to write a script that will be a scheduled job, part of this needs to be if a file exists it will not mov the new file into the area concerned, if it does not exist it will copy it, does a what if command exist in DOS,
the OS is is Windows 2000 Server and i am writing a batch file that will FTP a file down then transfer the file to another area for processing , this file name will always be the same, so if the previous one is still there the new one cannot go into the folder, the new file has to wait until this one has been processed
Thank you all in anticipation
ASKER
needs to be silent and not prompt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi All
Thanks for the input thus far, is there anyway I could insert a sleep command
so it would loop sleep whilst the file is there, once the previous file had been processed it would then copy
many thanks in anticipation
Thanks for the input thus far, is there anyway I could insert a sleep command
so it would loop sleep whilst the file is there, once the previous file had been processed it would then copy
many thanks in anticipation
Hi. Sorry for the delay.
What I would do is write a second batch file that contains the commands you need to process the first file, if it exists (call it, say, process.bat). Then
If exist path\filename call process.bat
{then your ftp and copy commands here}
What I would do is write a second batch file that contains the commands you need to process the first file, if it exists (call it, say, process.bat). Then
If exist path\filename call process.bat
{then your ftp and copy commands here}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
I feel this will do the job:
::-----8<----filename.bat- ---------- -----
@echo off
:start
if not exist dir\file.ext goto start
REM # Add your code here.
::------------------------ ---------- --------
NOTE: in my experience, not ALL versions of DOS can run "if NOT exist". If this is the case for you, then replace:
if not exist dir\file.ext goto start
with:
if exist dir\file (
REM # File exists, continue to run code.
) ELSE (
REM # File does not exist, loop back.
goto start
)
This will create an infinite loop while the file does not exist, but once the file exists, and is recognised by the batch, it will run the code that you want.
:o)
[R.d]
I feel this will do the job:
::-----8<----filename.bat-
@echo off
:start
if not exist dir\file.ext goto start
REM # Add your code here.
::------------------------
NOTE: in my experience, not ALL versions of DOS can run "if NOT exist". If this is the case for you, then replace:
if not exist dir\file.ext goto start
with:
if exist dir\file (
REM # File exists, continue to run code.
) ELSE (
REM # File does not exist, loop back.
goto start
)
This will create an infinite loop while the file does not exist, but once the file exists, and is recognised by the batch, it will run the code that you want.
:o)
[R.d]
{do your stuff here}
will only process the commands after "if not exist" if the file does not exist.