Solved

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

Posted on 2011-09-20
9
408 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 53

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Problems using Powershell and Active Directory?

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

Suggested Solutions

Title # Comments Views Activity
powershell add-content , set-content 2 23
Find newest file of each subfolder 4 26
Batch script to check for file size and delete/keep 3 21
powershell and invoke-command 4 23
Synchronize a new Active Directory domain with an existing Office 365 tenant
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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