Solved

How to empty folder of files in 10 file chunks with pause between chunks

Posted on 2011-09-20
9
420 Views
Last Modified: 2012-05-12
I have a folder that gets loaded with files via robocopy scripts.  I need to move the files into a final processing folder 10 files at a time, in no particular order, with a minute or so pause between chunks. The incoming files are pdf, rtf and doc.

I use Robocopy a good bit but haven't been able to make sense out of how to do it.  

I am not stuck to Robocopy, but it does need to be able to run in a bat file.

Thanks in advance for the help.
0
Comment
Question by:mholbert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 62 total points
ID: 36571629
Hi, this is VBS, but you can run it from a batch file using
cscript //NoLogo "C:\Scripts\MoveFiles.vbs"

Regards,

Rob.
strSourceFolder = "C:\Incoming"
strTargetFolder = "C:\Processing"
intSecondsToWait = 60
intMaxFileBatch = 10

If Right(strTargetFolder, 1) <> "\" Then strTargetFolder = strTargetFolder & "\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
intFile = 1
For Each objFile In objFSO.GetFolder(strSourceFolder).Files
	WScript.Echo "Moving " & objFile.Path
	objFSO.MoveFile objFile.Path, strTargetFolder
	intFile = intFile + 1
	If intFile = intMaxFileBatch Then
		WScript.Echo "Waiting " & intSecondsToWait & " seconds..."
		WScript.Sleep intSecondsToWait * 1000
		intFile = 1
	End If
Next

Open in new window

0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 63 total points
ID: 36573044
Just for variety, here's a BAT solution.  Adjust SETs as needed.

@echo off
setlocal EnableDelayedExpansion

REM Set source and destination folder, as well as how many fiels to move at a time
REM Delay is in milliseconds (seconds to delay * 1000)
set BaseDir=c:\temp
set DestDir=d:\temp
set Chunk=10
set Delay=60000

REM Main loop to look for the next group of files to move
:Loop
  set Count=0
  REM Process up to group size of files
  for %%A in ("%BaseDir%\*.*") do (
    set /A Count+=1
    if !Count! GTR %Chunk% goto :Wait
    echo Moving [%%~A] to [%DestDir%]
    move "%%~A" "%BaseDir%">NUL
  )

REM Delay for the desired time and then look again
:Wait
  ping 1.1.1.1 -n 1 -w %Delay%
  goto :Loop

Open in new window

~bp
0
 

Author Closing Comment

by:mholbert
ID: 36573121
I will try both and see which is faster.  I appreciate the help.  MH
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mholbert
ID: 36573244
I just modified and tested the bat solution provided by BillPrew.  the command window reports it is moving the files, but the files don't move.  There is nothing in event viewer to indicate the problem.

Thoughts?  MH
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36573290
Did it display the

Moving [c:\temp\file1.txt] to [d:\temp]

type message, and if so can you paste here?  If it did, does the DestDir already exist, and do you have write permission to it?

If that doesn't work, remove the ">NUL" from the MOVE line and rerun looking for an error to be reported there.

~bp
0
 

Author Comment

by:mholbert
ID: 36573636
the final bat is as follows:  

REM   Move 30 files at a time into \\Ferret\OmniPage\LAB from \\Ferret\OmniPage\LabHold


@echo off
setlocal EnableDelayedExpansion

REM Set source and destination folder, as well as how many files to move at a time
REM Delay is in milliseconds (seconds to delay * 1000)
set BaseDir=\\ferret\omnipage\LabHold
set DestDir=\\ferret\omnipage\LAB
set Chunk=30
set Delay=60000

REM Main loop to look for the next group of files to move
:Loop
  set Count=0
  REM Process up to group size of files
  for %%A in ("%BaseDir%\*.*") do (
    set /A Count+=1
    if !Count! GTR %Chunk% goto :Wait
    echo Moving [%%~A] to [%DestDir%]
    move "%%~A" "%BaseDir%"
  )

REM Delay for the desired time and then look again
:Wait
ping 1.1.1.1 -n 1 -w %Delay%
goto :Loop

When run via a command window, it reports the following:  I only pasted three lines of the output, in reality the output is 10 lines, one per file.  Permissions appear to be appropriate, i removed the >Nul and did not see any change

Moving [\\ferret\omnipage\LabHold\20708.PDF] to [\\ferret\omnipage\LAB]
        1 file(s) moved.
Moving [\\ferret\omnipage\LabHold\20715.PDF] to [\\ferret\omnipage\LAB]
        1 file(s) moved.
Moving [\\ferret\omnipage\LabHold\20734.PDF] to [\\ferret\omnipage\LAB]
        1 file(s) moved.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36573657
Hi,

One thing, you have
    echo Moving [%%~A] to [%DestDir%]
    move "%%~A" "%BaseDir%"

where the echo is %DestDir% but the move is %BaseDir%

You should get away with just changing
    move "%%~A" "%BaseDir%"

to
    move "%%~A" "%DestDir%"


As it was, the file was just moving over itself.

Rob.
0
 

Author Comment

by:mholbert
ID: 36573791
That did it, i guess i should have read the stuff myself.  I appreciate the quick fix.  MH
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36574123
Sorry, my bad, thanks Rob.

~bp
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question