PLEASE HELP!!!!
I went a little different route, maybe you can find something useful here.
I pulled the list of files into a temp workbook and sorted on last date
modified and then take the 5 oldest and moved them to a second folder.
Good luck
david kinn
Sub CopyOldestFiles()
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\ATest")
Set tmp = Workbooks.Add
Set myfiles = f.Files
counter = 1
For Each fc In myfiles
tmp.Sheets(1).Cells(counter, 1).Value = fc.Name
tmp.Sheets(1).Cells(counter, 2).Value = fc.datelastmodified
counter = counter + 1
Next
tmp.Sheets(1).Columns("B:B").EntireColumn.AutoFit
tmp.Sheets(1).Range(Selection, Selection.End(xlToRight)).Select
tmp.Sheets(1).Range(Selection, Selection.End(xlDown)).Select
Set sortrange = Selection
tmp.Worksheets("Sheet1").Sort.SortFields.Clear
tmp.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With tmp.Worksheets("Sheet1").Sort
.SetRange sortrange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For Count = 1 To 5
Set f2 = fso.GetFile("c:\ATest\" & tmp.Sheets(1).Cells(Count,
1).Value)
f2.Move ("C:\BTest\" & tmp.Sheets(1).Cells(Count, 1).Value)
Next Count
tmp.Close False
Set tmp = Nothing
End Sub
" wrote:
Tom,
Thanks for your help
Now that it only deletes the 10 files (5 txt and 5 dat) I can keep all
of the files in those two folders with out transfering.
All of these files are on a server at work so I can get them droped
into those files instead.
The problem I am having know is the renaming.
You answered on of my first posts about remaming unknow files and the
macro renames the files 1-5000 (whatever amount I have in the folder)
here is the problem...... The first time I put in the files it works
then I delete the 5 files I have already used and when I go back to
rename them the second time it doesn't necessarily rename them 1-5 it
may go 1,4,6,8,9,23. It seems to be random which means that when my
macro searches for dat and txt files 1-5 it won't find them.
I am so close to perfecting this thing but at the same time I can't
see the light at the end of the tunnel.
Thanks for all your help
|