Solved

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

Posted on 2011-09-20
9
398 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 51

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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

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 51

Expert Comment

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

~bp
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now