Jump to content

Batch Script: How to Set the Number of Files to Copy or Move


Recommended Posts

Posted

HI All,

 

I'm very new batch programming and have a question about a task.

 

I'm looking to create a batch programming script where I can copy 10 files at a time

 

every 10 minutes to a destination folder until all files have been copied

 

ex: select 1st 10 files to copy over,wait 10 minutes, then copy next 10 files and so on.

 

This is like a for loop, but confused on how to set it up.

 

I've played around with robocopy cmd but I can only copy all files to a destination folder.

 

ex: I want to copy from this drive: C:\Users\austid02\Desktop\test

 

place files into this folder path: C:\Users\austid02\Desktop\test2

 

thanks in advance very grateful!

 

Darell

  • Thanks 1
Posted

Hi there, I know how to do robocopy to copy all files from source to destination, but what I don't know how to do is to set up the syntax of how to select 10 files at a time

from a folder every 10 minutes until all files have been copied.

 

I never did batch programming before and i'm learning really on the fly. Any samples of this would be greatly appreciated :-)

 

Thanks

Posted (edited)

The way I'd do it isn't the most efficient but its late on a Friday and it's how I usually do these things.

 

do a dir /b > filelist.csv

 

which would result in

 

file1.txt

file2.txt etc

 

 

open the filelist.csv in excel, insert columns so you end up with copy file1.txt destination folder

 

e.g.

 

A1, A2, A3

copy, C:\Users\austid02\Desktop\test\file1.txt, c:\C:\Users\austid02\Desktop\test2\

copy, C:\Users\austid02\Desktop\test\file2.txt, C:\Users\austid02\Desktop\test2\

every ten rows add timeout /t 600 /nobreak > NUL

 

save csv

 

edit csv in notepad++ or similar and replace commas with spaces

 

save as a .bat file

 

run batch file in source folder

 

Might work, like I said it's close to beer o clock tho :)

Edited by caffrey
  • Thanks 2
Posted

Hi all, I found a solution and it's posted below!

 

Thanks to everyone

@echo offset Source=C:\Users\austid02\Desktop\testset Target=C:\Users\austid02\Desktop\test2set MaxLimit=10for /f "tokens=1* delims=[]" %%G in ('dir /A-D /B "%Source%\*.*" ^| find /v /n ""') do ( copy /y "%Source%\%%~nxH" "%Target%" if %%G==%MaxLimit% exit /b 0)

  • Thanks 1
  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...