Copy and move and rename file MS-ACCESS VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 73429
    New Member
    • Aug 2020
    • 7

    Copy and move and rename file MS-ACCESS VBA

    Hi i have a a database that i use a cmd that use the filecopy method
    i want to accomplish is to rename the files to a consecutive numbers order
    could anyone be a help
    thank you
  • cactusdata
    Recognized Expert New Member
    • Aug 2007
    • 223

    #2
    If you can accept to compress the file before copying, you can use one of my functions right away:
    • zip
    • cab
    • tar
    found in my repository at GitHub:
    Zip/unzip or cab/decab files and folders in VBA. Contribute to GustavBrock/VBA.Compress development by creating an account on GitHub.

    Or you can modify the code stub that controls the versioning to fit your need:
    Code:
    ZipFile = FileSystemObject.BuildPath(ZipPath, ZipName)
    
    If FileSystemObject.FileExists(ZipFile) Then
        If OverWrite = True Then
            ' Delete an existing file.
            FileSystemObject.DeleteFile ZipFile, True
            ' At this point either the file is deleted or an error is raised.
        Else
            ZipBase = FileSystemObject.GetBaseName(ZipFile)
            ExtensionName = FileSystemObject.GetExtensionName(ZipFile)
            Extension = "." & ExtensionName
            
            ' Modify name of the zip file to be created to preserve an existing file:
            '   "Example.zip" -> "Example (2).zip", etc.
            Version = Version + 1
            Do
                Version = Version + 1
                ZipFile = FileSystemObject.BuildPath(ZipPath, ZipBase & Format(Version, " \(0\)") & Extension)
            Loop Until FileSystemObject.FileExists(ZipFile) = False Or Version > MaxZipVersion
            If Version > MaxZipVersion Then
                ' Give up.
                Err.Raise ErrorPathFile, "Zip Create", "File could not be created."
            End If
        End If
    End If
    ' Set returned file name.
    Destination = ZipFile

    Comment

    • 73429
      New Member
      • Aug 2020
      • 7

      #3
      Hi
      i want it should copy and rename any file format
      any advise ?

      Comment

      • cactusdata
        Recognized Expert New Member
        • Aug 2007
        • 223

        #4
        My code above will copy any file extension.

        Comment

        • 73429
          New Member
          • Aug 2020
          • 7

          #5
          Hi
          thanks for your respond
          i don't want the files to be saved as zip file
          any advise
          thank you

          Comment

          • cactusdata
            Recognized Expert New Member
            • Aug 2007
            • 223

            #6
            Again: the code above will copy any file extension. Why don't you try?

            Comment

            • 73429
              New Member
              • Aug 2020
              • 7

              #7
              correct but will it be saved as zip ?

              Comment

              • cactusdata
                Recognized Expert New Member
                • Aug 2007
                • 223

                #8
                Only if it was a zip file. Why don't you try?

                Comment

                Working...