Looking for a script to do an advanced file copy procedure.

By Drew McClure ·
I'm looking for a script, tool, or program that will do the following. Check the size of a folder, if said folder meets the requirements, continue and check the date of the oldest file. If the file is older than said time and date move the file out of that folder into another folder. I'm pretty sure a VBS script will do it but I'm not a programmer. I already thought robocopy and xxcopy would do this but they won't.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Yes, it can be done...

by scott_heath In reply to Looking for a script to d ...

I personally suggest you learn VBScript and Powershell. Scripting is a must for administration today and it provides you a clear edge over Admins who "fear" becoming a programmer. I script all sorts of tasks and it has boosted my visibility and career. And it isn't really that tought when you get started.

I'll try to bang something out today and post it here for you to take a look at.

Collapse -

If your a dummy like me....

by DaveDXB In reply to Yes, it can be done...

This may not be what your looking for...but i thinks its very cool and is something u have to have a look at :)

and its freeware

Collapse -


by scott_heath In reply to If your a dummy like me.. ...

I totally support using this program, but I suggest you learn vbscript as well.

I actually use the AutoITX3.dll in a couple of my scripts as it adds functionality. The downside is having to have the DLL registered on the PC running the script. For me it was the easiest way to disable keyboard input short of writing a C program, which did mesh with the rest of what I was doing.

Collapse -

Here ya go...

by scott_heath In reply to Looking for a script to d ...

'Written by Scott Heath, 10/10/2007

Dim reqsize, fso, Folder, Files, File, OldestFile, tempvar, currdiff, FileToMove

'this will be used when tracking the oldest date
tempvar = 0
currdiff = 0

'The folder size is returned in bytes.
'There are 1048576 bytes per megabyte
'adjust the second number to the threshold
'you are looking for in megabytes
reqsize = 1048576 * 0

'We create the File System Object and
'an object that point to a folder
'Change c:\temp to whatever your folder name is
Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.GetFolder("c:\temp")

'Now we check to see if the folder is
'over the threshhold limit
'Then if it is we get all the files
'and check each one to see if it is older than
'the previous file.
If Folder.Size > reqsize Then
Set Files = Folder.Files
For Each File in Files
currdiff = DateDiff("s", File.DateLastModified, Now)
If currdiff > tempvar Then
OldestFile = File.Path
tempvar = currdiff
End If
End If

'Copy the oldest file to another directory
'Change c:\temp2 to the destination
'of your choice.
Set oFileToMove = fso.GetFile(OldestFile)

Related Discussions

Related Forums