Page 1 of 1

simple batch file

Posted: 13 Jan 2016 04:24
by dirkaulo
I am making a script to move all files from "C:\temp\source" to "C:\temp\destination".
While for every 7 files copied, I would like to sleep for 20 seconds.
I've been working so hard but it still doesn't work.
Below with my batch, could anyone give me some idea?
Thanks a lot!



Code: Select all

@ECHO OFF
ECHO.

set i=0

for /f %%f in ('dir /b C:\test\source') do (
   %i%=%i%++
   move /y file C:\test\destination
   if "%i%" %% 7 =="0" (
   echo "Copied and sleep now"
   sleep 20
   ) else (
   echo "Copied"
   )
   )

Re: simple batch file

Posted: 13 Jan 2016 04:38
by foxidrive
Type set /? and read the help for the /a switch.

You can ask further questions if you need to after reading it.

Re: simple batch file

Posted: 13 Jan 2016 07:34
by Squashman
And just for the sake of not delaying the batch file when it does not need to be delayed I would check for the delay at the beginning of your FOR construct. So essentially check when it is the 8th file. If you only have 7 files and you do the delay after the 7th file you are delaying for 20 seconds for no reason.

Re: simple batch file

Posted: 13 Jan 2016 16:16
by trebor68
I have change your code.

Here my code:

Code: Select all

@ECHO OFF
ECHO.

SETLOCAL EnableExtensions EnableDelayedExpansion

set i=0

for /f "tokens=*" %%f in ('dir /b D:\Versuch\source') do (
  set /a i+=1, help="i %% 7"
  move /y "D:\Versuch\source\%%f" D:\Versuch\destination >nul

  if "!help!"=="0" (
    echo "%%f"  -  "Copied and sleep now"
    TIMEOUT 20 /nobreak
  ) else (
    echo "%%f"  -  "Copied"
  )
)


Please change the folders D:\Versuch to your folder names.
When your folder name have space characters (folder: D:\Versuch\destination) then use the quotation marks.