|
Answer» HI All,
I want to copy the file to a folder with success counter and else failure counter. if the file already exists it should sleep for few seconds. then it should continue till the numbers which i had entered as a 1st parameter.
i was trying this as below program, i was not correct, i am missing some thing. kindly guide where i am doing the error.
regards, mohamed asif kp
@Echo Off Echo.
SET /P COPIES=Please enter the number of files to copy (numbers only) : SET /P SRCDIR=Please enter source Directory(example c:\t3\) : SET /P SRCFILE=Please Enter Source File Name (example TEST) : SET /P DESDIR=Please enter Destination Directory(example c:\t3\) :
:CONTINUE If EXIST %SRCDIR%%SRCFILE% ( SLEEP 2 copy %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%%%A.txt SUCCESS = SUCCESS + 1 ) ELSE ( FAILURE = FAILURE + 1 TOTAL = SUCCESS+FAILURE IF TOTAL != COPIES GOTO CONTINUE ELSE GOTO END
:END
ECHO SUCCESS ECHO FAILURE
There are easier ways to do this, but I just followed along your train of thought. %%A is not a defined name so I improvised a bit.
Code: [Select]@Echo Off Echo.
SET /P COPIES=Please enter the number of files to copy (numbers only) : SET /P SRCDIR=Please enter source Directory(example c:\t3\) : SET /P SRCFILE=Please Enter Source File Name (example test) : SET /P DESDIR=Please enter Destination Directory(example c:\t3\) :
set /a success=0 set /a failure=0 set /a total=0
:CONTINUE If exist %SRCDIR%%SRCFILE% ( SLEEP 2 call set /a SUCCESS=%%SUCCESS%%+1 copy %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%%success%.txt ) ELSE ( call set /a FAILURE=%%FAILURE%%+1 ) call set /a TOTAL=%SUCCESS%+%FAILURE%
IF %TOTAL% neq %COPIES% (GOTO CONTINUE) ELSE GOTO END
:END ECHO %SUCCESS% ECHO %FAILURE%
Try checking out the for command with the /L switch which would provide a token to make the output files unique and COULD double as the counter for the loop.
Good luck. @ECHO Off
SET /P COPIES=Please enter the number of files to copy (numbers only) :
SET /P SRCDIR=Please enter source Directory (example c:\t3\) :
SET /P SRCFILE=Please Enter Source File Name (example test) :
SET /P DESDIR=Please enter Destination Directory (example c:\t3\) :
SET /A SUCCESS=0
SET /A FAILURE=0
ECHO %DESDIR%%SRCFILE%.txt ECHO %SRCDIR%%SRCFILE%.txt
IF NOT EXIST %DESDIR%%SRCFILE%.txt (GOTO :ONE) ELSE GOTO :TWO
:ONE COPY %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%.txt SET /A SUCCESS=%SUCCESS%+1 ECHO SUCCESS%SUCCESS% GOTO END
:TWO :CONT SET /A FAILURE=%FAILURE%+1 SLEEP 9
IF NOT EXIST %DESDIR%%SRCFILE%.txt (GOTO :ONE) ELSE GOTO :TWO ECHO FAILURE%FAILURE%
GOTO END
:END
|