Results 1 to 4 of 4
  1. #1
    daveofgv is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    18

    Copying multiple files?

    I am trying to create a simple access program that will copy files from one location to another.



    What I have is a list of filenames (200-1000) that I need to search a directory and copy the files to another directory once found. I need the program to create a value (1) when file is not found.

    I understand copying files, however, its hardcoded and only can copy one or two files.

    Can anyone help with showing me?

    What I need is having column "A" with all the file names and it searches the directory and copy once found.......

    I am not asking anyone to do it for me, however, I dont know access that well and need so major guidance.

    Thanks in advanced

    daveofgv

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you can copy files a number of ways. regardless of your method though, you should probably use Allen Browne's directory list code to sift through the files first. On every loop, you can simply throw a DOS command out there, or use the file system object. that also has a copy method. And if I remember right, VBA itself has a copy command. I know for a fact that it has a NAME command that renames files.

    Another thing to note is that with a large number of files that need attention like this, Access will most definitely freeze up on you when it's processing the loop requests. I've done this a million times. The freezing of the program, for me anyway, isn't usually a problem unless it lasts more than 10 seconds or so. If a situation like that, it ends up being continuous. I think after a period of time the memory stacking becomes corrupt or something. I don't know enough about memory stacking to tell you for

    But you can always stop that from happening by breaking your code on pre-determined loop runs. Like one break every 500 or something. That's the way I always prevent it.

    Here's AB's 3 procedures that he has posted on his site. Ignore all of the comments, as I've used this way too much since I originally copied it:

    Code:
    Public Function ListFiles2(strPath As String, Optional strFileSpec As String, _
                               Optional bIncludeSubfolders As Boolean)
                               
    On Error GoTo Err_Handler
    Dim td As TableDef, S As String
    Dim i As Long
    i = 1
        'Purpose:   List the files in the path.
        'Arguments: strPath = the path to search.
        '           strFileSpec = "*.*" unless you specify differently.
        '           bIncludeSubfolders: If True, returns results from subdirectories of strPath as well.
        '           lst: if you pass in a list box, items are added to it. If not, files are listed to immediate window.
        '               The list box must have its Row Source Type property set to Value List.
        'Method:    FilDir() adds items to a collection, calling itself recursively for subfolders.
        Dim colDirList As New Collection
        Dim varItem As Variant
        
        Call FillDir2(colDirList, strPath, strFileSpec, bIncludeSubfolders)
        
        'Add the files to a list box if one was passed in. Otherwise list to the Immediate Window.
        'THIS FOR-EACH LOOP HAS ALL OF MY CODE IN IT.  YOU DO WHATEVER YOU WANT WITH EACH FILE IT RUNS THROUGH.  
        'OTHER THAN THE LOOP CODE, ALL OF IT IS MINE AND NOT PART OF ALLEN BROWNE'S ORIGINAL POSTING ON HIS SITE.
    
             For Each varItem In colDirList
                Name CStr(varItem) As Replace(CStr(varItem), ", ", "__")
    
                's = TxtReadAll1(CStr(varItem))
                's = Replace(s, """", "_DOUBLE_QUOTES_")
                'Call TxtWrite1(s, CStr(varItem))
                
                'Name varItem As Replace(varItem, ",", "__")
                'DoCmd.TransferText acImportDelim, , _
                                   "_" & Mid(CStr(varItem), (InStrRev(CStr(varItem), "\") + 1), _
                                   ((InStrRev(CStr(varItem), ".") - (InStrRev(CStr(varItem), "\") + 1)))), _
                                   CStr(varItem), 0
                If Len(CStr(i / 10)) = 1 Then
                   MsgBox "break"
                End If
                     
                   's = "_" & Mid(CStr(varItem), InStrRev(CStr(varItem), "\") + 1, _
                                   (Len(Mid(CStr("c:\dosf\assoc.txt"), _
                                   InStrRev(CStr("c:\dosf\assoc.txt"), "\") + 1)) - 4))
                   'Debug.Print s & " " & CStr(i)
                   i = i + 1
            Next
    
    Exit_Handler:
        Exit Function
    
    Err_Handler:
        MsgBox "Error " & err.Number & ": " & err.Description
        Resume Exit_Handler
    End Function
    
    Private Function FillDir2(colDirList As Collection, ByVal strFolder As String, strFileSpec As String, _
        bIncludeSubfolders As Boolean)
        'Build up a list of files, and then add add to this list, any additional folders
        Dim strTemp As String
        Dim colFolders As New Collection
        Dim vFolderName As Variant
    
        'Add the files to the folder.
        strFolder = TrailingSlash2(strFolder)
        strTemp = Dir(strFolder & strFileSpec)
        Do While strTemp <> vbNullString
            colDirList.Add strFolder & strTemp
            strTemp = Dir
        Loop
    
        If bIncludeSubfolders Then
            'Build collection of additional subfolders.
            strTemp = Dir(strFolder, vbDirectory)
            Do While strTemp <> vbNullString
                If (strTemp <> ".") And (strTemp <> "..") Then
                    If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
                        colFolders.Add strTemp
                    End If
                End If
                strTemp = Dir
            Loop
            'Call function recursively for each subfolder.
            For Each vFolderName In colFolders
                Call FillDir2(colDirList, strFolder & TrailingSlash2(vFolderName), strFileSpec, True)
            Next vFolderName
        End If
    End Function
    
    Public Function TrailingSlash2(varIn As Variant) As String
        If Len(varIn) > 0& Then
            If Right(varIn, 1&) = "\" Then
                TrailingSlash2 = varIn
            Else
                TrailingSlash2 = varIn & "\"
            End If
        End If
    End Function

  3. #3
    daveofgv is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Feb 2011
    Posts
    18
    Here's AB's 3 procedures that he has posted on his site
    Which one would be the best?

    I will have filenames in one column:
    23432425.tif
    53256424.tif
    35632344.tif

    etc......

    I would need them searched in a particular directory (subfolders also) and copied to another folder......

    then either "1" or "Not Found" next to each file not found.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by daveofgv View Post
    Which one would be the best?
    .
    umm...they all need to be used together, bud. the big one is the only one you'll use for arguments.

    skimming through the code, you'll find that out.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import multiple text files automatically
    By instructorTek in forum Import/Export Data
    Replies: 30
    Last Post: 10-20-2012, 04:50 PM
  2. Perform an operation on multiple files.
    By newuser in forum Access
    Replies: 9
    Last Post: 11-18-2010, 11:21 AM
  3. output to multiple pdf files
    By geoffishere in forum Reports
    Replies: 1
    Last Post: 07-04-2010, 03:39 PM
  4. Replies: 2
    Last Post: 05-25-2010, 02:45 PM
  5. Importing multiple files at once
    By NoiCe in forum Import/Export Data
    Replies: 1
    Last Post: 04-01-2009, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums