?
Solved

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

Posted on 2011-09-20
9
Medium Priority
?
428 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 248 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 56

Accepted Solution

by:
Bill Prew earned 252 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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 56

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 56

Expert Comment

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

~bp
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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