Check if file is copied

October 29, 2009 at 14:41:41
Specs: Windows XP
Basically I want to do something like the
following.
set counter = 0

:copyFile
counter /a += 1
copy files....

if (print screen) = "The system cannot find the
path specified" {
timeout 3600
goto copyFile
if (counter) >= 5 {
break
}
}

so I want to check if file is being copied. if not
then wait for some amount of time and then try
to copy again.


See More: Check if file is copied

Report •


#1
October 29, 2009 at 14:42:34
sorry the if statement should be in front of the goto copyFile

Report •

#2
October 29, 2009 at 20:51:05
So I'm assuming that you are looking to do the following? Obviously you still have to do some modifications to get this all to work for you. Like tell it what file you want to copy. Also What file to check for existance? and then to use the ping command for your delay is in miliseconds so 5000 is equal to 5 seconds and then above you had your if statement saying if counter is greater then or equal to 5 to go back and loop, which I changed to Less then or Equal to 5, which would make it run through the loop 6 times before stopping.
Also Above you have "Break" tied in there, not exactly sure what you want to achieve with that so I replaced it with a pause?


@echo off
set /a counter = 0

:copyFile
set /a counter += 1
copy files...

if not exist "C:\file.???" (
PING 1.1.1.1 -n 1 -w 5000 >NUL
)
if %counter% LEQ 5 goto copyfile
Set counter=
pause


Report •

#3
October 30, 2009 at 10:04:16
I guess I want to check if the file copied.
because there is new version of the file everyday.

Report •

Related Solutions

#4
October 30, 2009 at 10:14:26
So... To check if the copy command was successful instead of if the file exists, we can just use there errorlevel, the following will check the errorlevel and try to copy the file every 5 seconds for a total of 6 tries if not successful.


@echo off
set /a counter = 0

:copyFile
set /a counter += 1
copy "C:\somefile.txt" "C:\Backup"

if ErrorLevel 1 (
PING 1.1.1.1 -n 1 -w 5000 >NUL
if %counter% LEQ 5 goto copyfile
)
Set counter=
pause


Report •

#5
October 30, 2009 at 10:47:27
would that trigger with all the files that I'm copying?
I just need to check against one particular file

Report •

#6
October 30, 2009 at 11:58:09
So if you only need it to check and loop back to the CopyFile label for one file, just use this for the above code for the one file specifically and then tack the rest of the copying either at the end just before the pause or before the :Copyfile

Report •

#7
October 30, 2009 at 14:06:43
I want it to terminate after not able to run it 5 times
this is what I have so far..but it exit every single time when I
come to the errorlevel part of the code

:copyFile
set/a terminationCounter += 1
copy "C:\somefile.txt" "C:\Backup"

if ErrorLevel 1(
PING 1.1.1.1 -n 1 -w 3600000 >NUL
if %counter% GEQ 5 (exit)
goto copyFile
)


Report •

#8
October 30, 2009 at 14:32:09
OKay to spread the if statement acrost multiple lines, you need a space between 1 and (
example: errorlevel 1 (
That is why it isnt' doing the waiting, next you will find that your terminationcounter isn't working either. You're setting the count in a variable named terminationcounter but your if statement is checking a variable named counter.

The following is your batch, just changed a couple a couple things, Added the space where needed, also renamed counter check in the if statement.


@echo off
:copyFile
set/a terminationCounter += 1
copy "C:\somefile.txt" "C:\Backup"

if ErrorLevel 1 (
PING 1.1.1.1 -n 1 -w 3600000 >NUL
if %terminationcounter% EQU 5 (exit)
goto copyFile
)


Report •


Ask Question