View Single Post
Old May 14th, 2005, 10:50 PM   #1
harjit
Newbie
 
Join Date: May 2005
Posts: 1
Rep Power: 0 harjit is on a distinguished road
Unhappy copying files first before deleting them

I have a program that purges files after a certain amount of days.My problem
is now to move the files that I wish to delete to an archive folder first before deleting them permanently so that users can still access those files if there's a need to.How do I do this?Can someone help me please?The codes are as follows (VB6)

Private Sub Form_Activate()
Dim fso As New FileSystemObject
Dim RootPath As String
Dim Report As String
Dim Path As String
Dim KeepDay As Integer
Dim root As Folder
Dim Fol1 As Folder
Dim Fol2 As Folder
Dim Fol3 As Folder
Dim File1 As File
Dim File2 As File
Dim vStart As Date
Dim vEnd As Date
Dim DelNum As Long
DelNum = 0
vStart = Now
RootPath = "E:\Xfiles\WIPFS\_AccMgr\Thruput\"
Open App.Path & "\Parameter.txt" For Input As #1
Do Until (EOF(1) = True)
KeepDay = 0
Input #1, KeepDay
Loop
Close #1
Open App.Path & "\DeletedFile.txt" For Output As #2
Set root = fso.GetFolder(RootPath)
For Each Fol1 In root.SubFolders
Set Fol2 = fso.GetFolder(RootPath & Fol1.Name)
For Each File1 In Fol2.Files
If DateDiff("d", File1.DateLastModified, Date) > KeepDay Then
Print #2, RootPath & Fol1.Name & "\" & File1.Name,
DateDiff("d", File1.DateLastModified, Date)
lblFile.Caption = RootPath & Fol1.Name & "\" & File1.Name
fso.DeleteFile RootPath & Fol1.Name & "\" & File1.Name
DelNum = DelNum + 1
End If
DoEvents
Next
Next
Close #2
vEnd = Now
Open App.Path & "\ExecutionLog.txt" For Append As #1
Print #1, "Start: " & vStart, "End: " & vEnd, "Successfully Delete " & DelNu
m & " Files."
Close #1
End
End Sub

I tried using this line fso.copyfile source, destination its suppose to be correct but it keeps giving me an error.Is it suppose to look like this

fso.copyfile "C:/harj" , "C:/harj/harj_copy"

OR

source = "C:/harj"
destination = "C:/harj/harj_copy"
fso.copyfile source, destination

Where exactly do I put these lines in my code?Please guide me as Im new to VB.Thank u so much in advance.
harjit is offline   Reply With Quote