Newbie question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thenath24
    New Member
    • Apr 2007
    • 10

    Newbie question

    Hello all,

    Im currently writing a small program that will be invoked has a scheduled task to back up all of the files froma directory on my C drive toa removable disk (F).

    I've tried using the following;

    system("copy c:\test\*.* f:\");

    (which is basically what I did at the command prompt to achieve the same thing)

    However when run the program runs it reports that the syntax of the command is incorrect

    Any one seen this before or know why?

    Nathan
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by thenath24
    Hello all,

    Im currently writing a small program that will be invoked has a scheduled task to back up all of the files froma directory on my C drive toa removable disk (F).

    I've tried using the following;

    system("copy c:\test\*.* f:\");

    (which is basically what I did at the command prompt to achieve the same thing)

    However when run the program runs it reports that the syntax of the command is incorrect

    Any one seen this before or know why?

    Nathan
    A backslash character in a literal string is special to the compiler, e.g. \n
    means a new line character and there are more of them. Since the backslash
    character is a special character by itself you need *two* of them to have
    *one* of them in your literal string, so:

    [code=c]
    system("copy c:\\test\\*.* f:\\");
    [/code]

    kind regards,

    Jos

    Comment

    • thenath24
      New Member
      • Apr 2007
      • 10

      #3
      Originally posted by JosAH
      A backslash character in a literal string is special to the compiler, e.g. \n
      means a new line character and there are more of them. Since the backslash
      character is a special character by itself you need *two* of them to have
      *one* of them in your literal string, so:

      [code=c]
      system("copy c:\\test\\*.* f:\\");
      [/code]

      kind regards,

      Jos
      Thanks Jo that worked a treat :-)

      Nathan

      Comment

      • Firecore
        New Member
        • Jul 2007
        • 114

        #4
        so does that mean that we can use system(); to use dos based commands?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by Firecore
          so does that mean that we can use system(); to use dos based commands?
          You've got it. Here's a nice reference web page for C/C++:

          C/C++ library reference; bookmark the url.

          kind regards,

          Jos

          Comment

          Working...