Solved

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

Posted on 2011-09-20
9
417 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
  • 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find Files older than 6 months and then ZIP the Files 4 29
size of file 1 22
Remote Powershell Issue 3 30
Ruby or Python 7 47
A brief introduction to what I consider to be the best editor for PowerShell.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

735 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