Announcement

Collapse
No announcement yet.

FileCopy with spaces in file name

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • FileCopy with spaces in file name



    I can't believe this one has me stumped, but...

    Trying to use FileCopy where the destination file has spaces in it, for example:
    "J:\Location\Department\Data Quality\3. Issues Tracking\Supporting Documentation\Emails\000203\abc.abc"

    I've tried all sorts of gubbins with Chr$(34), multiple quote marks and just about every possible permutation thereof but always get an Error 52 (Bad file name or number). This is related to the destination filename with the spaces. I can FileCopy Source, Source & "XXX" (for example) no problem

    I can also copy the file using Windows Explorer, using a DOS box and a Copy command with quotes around the filename, but no way is it going to happen in code.

    I would appreciate someone else's perspective of this before I start barking...

  • #2
    Re: FileCopy with spaces in file name

    I am unable to reproduce the error:
    Code:
    FileCopy "C:\Documents and Settings\xxxxx xxxxx\My Documents\Excel\Ozgrid\3. Issues Tracking\File Copy Test 146683.xls", _
                "C:\Documents and Settings\xxxxx xxxxx\My Documents\Excel\Ozgrid\3. Issues Tracking\File Copy Test 2 146683.xls"
    Works just fine for me. (Well it does without me obliterating my real details )

    Comment


    • #3
      Re: FileCopy with spaces in file name

      Thanks Rob - at least it's just me for once.

      I do understand the name must be enclosed in "'s if it includes spaces and I check for that - but for one reason or another it just will not copy to that directory using the variable.

      However, It does copy if I replace the variable with a literal - so back to squinting at the multiple """""'s

      Comment


      • #4
        Re: FileCopy with spaces in file name

        My guess is that you aren't joining the variables correctly, or they don't contain the right file/path names and are perhaps missing a back-slash \ . In other words the problem is not the spaces.

        Comment


        • #5
          Re: FileCopy with spaces in file name

          A good tip from Barb-b here on ozgrid is to create two constants:
          Code:
          Const Q = Chr(34)
          Const DQ = Chr(34) & Chr(34)
          Then use them when appropriate. Tends to avoid going bleary eyed counting the little ticks.

          Comment


          • #6
            Re: FileCopy with spaces in file name

            Thanks for the suggestions - and I always use Chr$(34) in preference to "'s, but this just will not work for me today.
            Strategy to resolve: Save, Shut down, go home, enjoy the weekend...

            Comment


            • #7


              Re: FileCopy with spaces in file name

              Sounds like a plan Cytop. Have a good one!

              Comment

              Working...
              X