locked
copy a directory from one location to another in VC++ RRS feed

  • Question

  • I want to check a directory exists in local project directory or not. If it doesn't exists i want to copy it from a specified directory to the current project directory in VC++

    How do i do that, can any one help me please... 


    • Edited by prkac Friday, May 6, 2011 9:19 PM edit
    Friday, May 6, 2011 6:28 PM

Answers

  • Use this syntax:

     

        System::IO::DirectoryInfo ^ TeraTerm = gcnew System::IO::DirectoryInfo("C:\\SomeFolder"); 

        bool exists = TeraTerm->Exists;

     

    or this:

     

        System::IO::DirectoryInfo TeraTerm("C:\\SomeFolder"); 

        bool exists = TeraTerm.Exists;

     

     

    • Proposed as answer by SimonRev Friday, May 6, 2011 8:00 PM
    • Marked as answer by prkac Friday, May 6, 2011 11:32 PM
    Friday, May 6, 2011 7:16 PM

All replies

  • Use this syntax:

     

        System::IO::DirectoryInfo ^ TeraTerm = gcnew System::IO::DirectoryInfo("C:\\SomeFolder"); 

        bool exists = TeraTerm->Exists;

     

    or this:

     

        System::IO::DirectoryInfo TeraTerm("C:\\SomeFolder"); 

        bool exists = TeraTerm.Exists;

     

     

    • Proposed as answer by SimonRev Friday, May 6, 2011 8:00 PM
    • Marked as answer by prkac Friday, May 6, 2011 11:32 PM
    Friday, May 6, 2011 7:16 PM
  • Thanks for the answer.

    could you give me any clue about how to copy etire directory to another


    prkac
    Friday, May 6, 2011 9:21 PM
  • SHFileOperation
    Nikita Leontiev
    Friday, May 6, 2011 9:54 PM
  • Thanks Nikita,

    But what ever examples i have seen about this function doesn't working...giving errors.

    mine is 64bit Windos 7 VS2008 (don't know whether this matters or not just giving info.)

    could you please provide me a best example.


    prkac
    Friday, May 6, 2011 10:30 PM
  • I  have used system("xcopy C:\sourcedir C:\destdir")

    And it is working now....is this the right way of doing?

    Please confirm   Thanks


    prkac
    • Marked as answer by prkac Friday, May 6, 2011 11:32 PM
    • Unmarked as answer by prkac Friday, May 6, 2011 11:33 PM
    Friday, May 6, 2011 11:03 PM
  • >SHFileOperation
    >But what ever examples i have seen about this function
    >doesn't working...giving errors.

    We can't help if you don't spell out the errors.

    >I have used system("xcopy C:\sourcedir C:\destdir")
    ....is this the right way of doing?

    Define "right". Your definition and ours may be different.

    How do you detect and handle errors when they happen?

    - Wayne


    Saturday, May 7, 2011 12:15 AM
  • I kept all the code in 'try' block and 'catch' for exception handling.

    so far it's working fine.

     

    Thanks everyone for the replies and your time.


    prkac
    Monday, May 9, 2011 8:22 PM
  • >system("xcopy C:\sourcedir C:\destdir")

    Note that if that's an actual line in your source
    code then the backslashes need to be doubled:

    system("xcopy C:\\sourcedir C:\\destdir")

    >I kept all the code in 'try' block and 'catch'
    >for exception handling.

    What good will that do if xcopy fails to find the
    source file or directory?

    Neither system nor xcopy will throw an exception
    if an error occurs.

    - Wayne
    Tuesday, May 10, 2011 1:06 AM
  • i am checking for the directory if it exists or not

    so if the dir is not there then it will execute this code....


    prkac
    Wednesday, May 11, 2011 10:18 PM