how to copy folder in c++?

This is a discussion on how to copy folder in c++? within the Windows Programming forums, part of the Platform Specific Boards category; hi ! i have a Data folder contain 2 file and some folders how can i copy this folder ? ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    34

    how to copy folder in c++?

    hi !
    i have a Data folder contain 2 file and some folders
    Name:  Untitled.jpg
Views: 1693
Size:  6.6 KB
    how can i copy this folder ?
    os:windows7...

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    Well a crude way would be to call system() to invoke the xcopy utility.

    Or maybe something based on this
    CopyFile function (Windows)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    does system() have any command to remove non empty directory?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    system() is just a programmatic way of doing whatever you could do at a console command prompt.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    is there any standard library for doing this stuffs?(copy move remove rename...)

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    There is no standard (yet), but Boost.Filesystem may be of help.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    It depends on how much effort you're willing to put into solving the problem.
    Sooner or later, API bloat stops and you have to start doing some things for yourself.

    For example, you could read this
    FAQ > Accessing a directory and all the files within it - Cprogramming.com

    Throw in some
    CreateDirectory function (Windows)

    Add a liberal sprinkling of
    CopyFile function (Windows)

    Perhaps some
    DeleteFile function (Windows)
    and
    MoveFile function (Windows)
    for good measure.

    You should do some reading to find out how compressed and/or encrypted files are dealt with as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    tnx salem and elysia
    i changed the win32 code(last example) and it seems to work and ofcource i dont know how!
    FAQ > Accessing a directory and all the files within it - Cprogramming.com

    would you recomend me a book for learning win32 ?
    tnx

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    I would strongly suggest you go as far as you can with boost rather than going the Win32 route. Win32 is Evil™.
    And if you want to do graphical user interfaces, you should pick up a GUI framework, such as Qt.
    Avoid Win32 like the plague. It's convoluted, bloated and just extremely difficult to use. Plus it's C, and not C++, which strongly limits your effectiveness when using C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Elysia View Post
    Avoid Win32 like the plague. It's convoluted, bloated and just extremely difficult to use. Plus it's C, and not C++, which strongly limits your effectiveness when using C++.
    Huh? I agree on the complexity and bloat, but Win32 is perfectly usable from C++.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Well yes, but I mentioned the effectiveness. It limits our ability to express powerful and flexible code as we typically do in C++.
    For example, for every resource we acquire, we must create some code to release that resource, be that some smart pointer + custom deleter or some new RAII object we write.
    Or for example, for every callback, we are required to use a global or a static class member function which typically take some weird callback types which we have to cast back to proper types. We can't send a class member, some arbitrary function or functor or a lambda, all with correct parameter types for what we know the callback will receive.

    I mean, it's like, if you are screwing screws and have an automatic screwdriver that works with those screws, why would you want to use a manual screwdriver, then? There is typically little point to "leaving" our rich and powerful universe unless we have a good reason for doing so.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Jun 2005
    Posts
    6,255
    Quote Originally Posted by Elysia View Post
    There is typically little point to "leaving" our rich and powerful universe unless we have a good reason for doing so.
    In our "rich and powerful universe" we have to use third party libraries or APIs like boost, win32, or Qt to do little things like building a GUI, doing more than basic file handling, accessing databases, and a whole lot of things that are useful.

    Win32, except for religious fanatics who intone that "Microsoft is evil" or "Win32 is evil" , is an option, no more. Like all of them, it has advantages and disadvantages.

    I'm all in favour of doing things in standard C++ if at all possible, and am delighted that C++-11 offers more facilities and supports more techniques than previous versions of C++. But pragmatism is concerned with solving problems, not crouching in some some perceived state of perfection within some "rich and powerful universe". Not even the greats of C++ would advocate such crouching - they are mostly interested in how to get jobs done.

    Incidentally, given that Microsoft is predominantly a C++ house, your characterising win32 as C is ironic. The C-like flavour of the win32 API is more about allowing it to be used across programming languages, rather than a homage to C.
    Right 98% of the time, and don't care about the other 3%.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by grumpy View Post
    Win32, except for religious fanatics who intone that "Microsoft is evil" or "Win32 is evil" , is an option, no more. Like all of them, it has advantages and disadvantages.
    I would argue that, unless there is something you cannot express in whatever language you are using and whatever libraries, frameworks and tools you are using, and you can express it in Win32, you should not use Win32.
    On a purely opinion way, it is ugly as hell, a pain to work with and is just disgusting, being built on old and dull foundations (as opposed to "syntax rich" foundations), and on a practical note, it is much easier to shoot yourself in the foot and it just takes more time to get the job done.
    That is, at least for a newbie.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy files in to a different folder help
    By TaiL in forum C Programming
    Replies: 4
    Last Post: 10-15-2009, 01:45 PM
  2. Folder copy
    By Salibea in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2005, 05:28 AM
  3. function to copy file from one folder to another
    By Harman in forum C Programming
    Replies: 7
    Last Post: 05-15-2005, 11:39 AM
  4. deleting a folder AND copying a folder
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 05-01-2004, 08:48 AM
  5. Copy Folder?
    By Antinaris in forum C++ Programming
    Replies: 1
    Last Post: 11-14-2003, 05:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21