Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2005
    Posts
    7

    Question Unanswered: Moving files to another folder (filename stored in a table)

    Hi

    How do I move files from one folder to another based on this information?

    Situation:
    I have a field on Table 1 that stores the matching filenames of the file and I'd like to use these filenames to move the actual files from location A to B (see details below)

    Detail:
    Table 1
    ----------------------------------
    Filename|Date
    ----------------------------------
    The quick..html | 27/11/2008
    Brown fox..html | 27/11/2008
    Jumped over..html | 27/11/2008
    The lazy dog..html | 27/11/2008

    A = C:\Source HTML\
    B = C:\Archived HTML\

    Can someone please give an example function to do this?

    Thank you.

  2. #2
    Join Date
    Jun 2005
    Posts
    7
    Hi All

    Problem solved with the function below:
    --------------------------------------------------------------------------
    Function MoveFilesToArchive()

    Dim A As String
    Dim B As String
    Dim objFSO As FileSystemObject
    Dim rst As Recordset
    Dim dbs As Database

    Set objFSO = New FileSystemObject

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Select Filename from Table 1")

    A = C:\Source HTML\ 'source folder
    B = C:\Archived HTML\ 'destination folder

    Do While Not rst.EOF

    If objFSO.FileExists(A & rst![Filename]) Then

    If objFSO.FileExists(B & rst![Filename]) Then
    objFSO.DeleteFile (A & rst![Filename])
    Else
    objFSO.MoveFile A & rst![FileName], B
    End If
    End If

    rst.MoveNext

    Loop
    -------------------------------------------------------------------------

    Maybe this will help a beginner like me. Thanks.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Brill! Glad you got it sorted and thank you for sharing the solution with the rest of us
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •