Scripting moving files

  • Thread starter Thread starter Jim Reed
  • Start date Start date
J

Jim Reed

Can somebody tell me how to automate file movement from
one directory to another then empty the first directory? I
am trying to write an event that will trigger a batch file
or something when the first place gets to a size then have
it to copy files so they can be backed up nightly.
 
This is based on the DateLastModified, you'll need to adjust it. Then
trigger it based on something that checks you dir size.

Dim fold1, fold2, f1, sf1, sf2, fso

Set fso = CreateObject("Scripting.FileSystemObject")


Set fold1 = fso.GetFolder("C:\RptLine")
Set fold2 = fso.GetFolder("C:\OldTrainFiles")
Set sf1 = fold1.Files
Set sf2 = fold2.Files

For Each f1 in sf1
If DateDiff ("d", f1.DateLastModified, Now) >= 30 Then
fso.CopyFile f1, "C:\OldTrainFiles\"
End If
Next
For Each f1 in sf2
If fso.FileExists (f1) Then
If DateDiff ("d", f1.DateLastModified, Now) >= 30 Then
If fso.FileExists ("C:\RptLine\" & f1.Name) Then
fso.DeleteFile ("C:\RptLine\" & f1.Name)
End If
End If
Next
For Each f1 in sf2
If DateDiff ("d", f1.DateLastModified, Now) >= 60 OR DateDiff ("d",
f1.DateLastModified, Now) < 30 Then fso.DeleteFile (f1)
Next

Set fso = Nothing
Set fold1 = Nothing
Set sf1 = Nothing
Set fold2 = Nothing
Set sf2 = Nothing

WSH 5.6 documentation download
http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
 
Jim Reed said:
Can somebody tell me how to automate file movement from
one directory to another then empty the first directory? I
am trying to write an event that will trigger a batch file
or something when the first place gets to a size then have
it to copy files so they can be backed up nightly.

Try this:
1 @echo off
2 set Source=c:\Some Folder
3 set Target=c:\Backup Folder
4 set Limit=20000000

5 for /F "tokens=3" %%a in ('dir /-c "%Source%" ^| find /i "file(s)"') do
set size=%%a
6 if %size% LSS %Limit% goto :eof

7 xcopy /d /y /c "%Source%" "%Target%\"
8 del /q "%Source%"

Remove the line numbers before running the script. To automate
the process, invoke the script via the Task Scheduler.
 
Back
Top