Home All Groups Group Topic Archive Search About

copying files first before deleting them

Author
14 May 2005 6:10 AM
harjit
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 " & DelNum & " Files."
Close #1
End
End Sub -- harjit ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------

Author
14 May 2005 9:47 PM
BeastFish
Eeee!  FSO! <g>

Instead of FSO, you can use the SHFileOperation API function with the
FO_MOVE parameter to move a file from one directory to another.  I'm on my
way out the door, going to a baseball game, so here's a quick sample off the
top of my head...

(General)(Declarations)
Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type

Private Declare Function SHFileOperation Lib "shell32.dll" _
        Alias "SHFileOperationA" _
        (lpFileOp As SHFILEOPSTRUCT) As Long

Private Const FO_MOVE = &H1
Private Const FOF_SILENT As Long = &H4              'don't create
progress/report
Private Const FOF_SIMPLEPROGRESS As Long = &H100    'don't show names of
files
Private Const FOF_NOCONFIRMATION As Long = &H10     'don't prompt the user.


(In some sub)
    Dim SHFileOp As SHFILEOPSTRUCT

    With SHFileOp
        .wFunc = FO_MOVE
        .pFrom = "C:\Original Path\Somefile.txt"
        .pTo = "C:\New Path\Somefile.txt"
        .fFlags = FOF_SILENT Or _
                  FOF_SIMPLEPROGRESS Or _
                  FOF_NOCONFIRMATION
    End With

    SHFileOperation SHFileOp




Show quote
"harjit" <harjit.1p1***@mail.codecomments.com> wrote in message
news:harjit.1p1htp@mail.codecomments.com...
>
> 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 " &
> DelNum & " Files."
> Close #1
> End
> End Sub
>
>
>
> --
> harjit
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
Author
15 May 2005 5:36 AM
J French
FileCopy   -  it is built into VB

On Sat, 14 May 2005 01:10:32 -0500, harjit
<harjit.1p1***@mail.codecomments.com> wrote:

Show quote
>
>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 " &
>DelNum & " Files."
>Close #1
>End
>End Sub
>
>
>
>--
>harjit
>------------------------------------------------------------------------
>Posted via http://www.codecomments.com
>------------------------------------------------------------------------
>

AddThis Social Bookmark Button