simple batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dirkaulo
Posts: 1
Joined: 13 Jan 2016 04:19

simple batch file

#1 Post by dirkaulo » 13 Jan 2016 04:24

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"
   )
   )

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: simple batch file

#2 Post by foxidrive » 13 Jan 2016 04:38

Type set /? and read the help for the /a switch.

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

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: simple batch file

#3 Post by Squashman » 13 Jan 2016 07:34

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.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: simple batch file

#4 Post by trebor68 » 13 Jan 2016 16:16

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.

Post Reply