Move files by time/date

  • Thread starter Thread starter Rpettis31
  • Start date Start date
R

Rpettis31

I receive text file "happy" downloads daily via an ftp. I want to be able to
move the files that are old to another folder "Happy old".
 
Not usre how you are determining old files. here is code to do the move. I
can give you more help if you tell me what criteria you are using to
determine the old files.

Set fs = CreateObject("Scripting.FileSystemObject")
'object.MoveFile source, destination
fs.movefile "c:\temp\abc.txt", "c:\temp\test\abc.txt"
 
I knew I forgot to mention something...Date/Time stamp on the file.
 
Try this code

Myfolder = "c:\Happy"
MyOldfolder = "c:\Happy Old"
Set fs = CreateObject("Scripting.FileSystemObject")
'object.MoveFile source, destination
first = True
Do
If first = True Then
Fname = Dir(Myfolder & "\*.txt")
first = False
Else
Fname = Dir()
End If

If Fname <> "" Then
Set fileobj = fs.getfile(Myfolder & "\" & Fname)
FDate = fileobj.DateLastModified
'get todays date
FDate = Int(FDate)
If FDate <> Date Then
fs.movefile Myfolder & "\" & Fname, _
MyOldfolder & "\" & Fname
End If

End If
Loop While Fname <> ""
 
This does dot move the files.

' select Move additional files from folder

CurrentFolder = "G:\Receiving\EXPEDITORS"
ArchiveFolder = "G:\Receiving\EXPEDITORS\Expo report Archive"
Set fs = CreateObject("Scripting.FileSystemObject")
' object.Movefile source, destination
first = True
Do
If first = True Then
Fname = Dir(Myfolder & "\*.txt")
first = False
Else
Fname = Dir()
End If

If Fname <> "" Then
Set fileobj = fs.getfile(CurrentFolder & "\" & Fname)
FDate = fileobj.DateLastModified

' get date
FDate = Int(FDate)
If FDate <> Date Then
fs.movefile CurrentFolder & "\" & Fname, _
ArchiveFolder & "\" & Fname
End If

End If

Loop While Fname <> ""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top