Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CopyFile problem

CopyFile problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphicshardware
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RoyceF
    wrote on last edited by
    #1

    Hi All, This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands: CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE ); All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem? Thanks, Royce

    C M T 3 Replies Last reply
    0
    • R RoyceF

      Hi All, This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands: CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE ); All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem? Thanks, Royce

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      RoyceF wrote:

      CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE );

      Don't you escape slashes?

      R 1 Reply Last reply
      0
      • C CPallini

        RoyceF wrote:

        CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE );

        Don't you escape slashes?

        R Offline
        R Offline
        RoyceF
        wrote on last edited by
        #3

        Yes, in the CString.Format() method call you do: CString str; str.Format( "C:\\Documents and Settings\\rfickling\\My Documents\\Expense Report Form.xls" ); I am actually formatting these file specs into CString variables so that it looks like the following: strSrc = "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls"; strDst = "Expense Report Form.xls" So the command in C++ syntax is: CopyFile( strSrc, strDst, FALSE ); This should work, but I get a 123 error.

        K C 2 Replies Last reply
        0
        • R RoyceF

          Hi All, This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands: CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE ); All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem? Thanks, Royce

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Error code 123 is "The filename, directory name, or volume label syntax is incorrect." Does this help narrow it down? *EDIT* You shouldn't have to add any double quotes because of spaces. -- modified at 18:10 Wednesday 22nd November, 2006

          1 Reply Last reply
          0
          • R RoyceF

            Yes, in the CString.Format() method call you do: CString str; str.Format( "C:\\Documents and Settings\\rfickling\\My Documents\\Expense Report Form.xls" ); I am actually formatting these file specs into CString variables so that it looks like the following: strSrc = "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls"; strDst = "Expense Report Form.xls" So the command in C++ syntax is: CopyFile( strSrc, strDst, FALSE ); This should work, but I get a 123 error.

            K Offline
            K Offline
            kakan
            wrote on last edited by
            #5

            I think the problem is the target file name. You are giving just a filename, so Windows tries to create the file in the current directory. And what's the current directory? Try giving a targetname with a complete path, if possible. Or make sure the current directory is set to where you want the file to be copied to. SetCurrentDirectory();

            Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

            1 Reply Last reply
            0
            • R RoyceF

              Yes, in the CString.Format() method call you do: CString str; str.Format( "C:\\Documents and Settings\\rfickling\\My Documents\\Expense Report Form.xls" ); I am actually formatting these file specs into CString variables so that it looks like the following: strSrc = "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls"; strDst = "Expense Report Form.xls" So the command in C++ syntax is: CopyFile( strSrc, strDst, FALSE ); This should work, but I get a 123 error.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              The following code works fine on my computer (Win2k):

              CString strSrc, strDst;
              strSrc.Format( "C:\\\\Documents and Settings\\\\Carlo\\\\My Documents\\\\Donald Duck.txt" );
              strDst.Format( "Donald Duck.txt" );
              
              if ( CopyFile( strSrc, strDst, FALSE )==FALSE)
              {
                    // some error handling...
              }
              
              1 Reply Last reply
              0
              • R RoyceF

                Hi All, This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands: CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE ); All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem? Thanks, Royce

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #7

                RoyceF wrote:

                CopyFile(

                instead of this use ShFileOperation

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

                R 1 Reply Last reply
                0
                • T ThatsAlok

                  RoyceF wrote:

                  CopyFile(

                  instead of this use ShFileOperation

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you

                  R Offline
                  R Offline
                  RoyceF
                  wrote on last edited by
                  #8

                  Thanks for the help, guys. I found that my problem was using the double quotes around the file paths and not specifiying a filename in the 2nd parameter. Royce

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups