Results 1 to 8 of 8

Thread: Creating, deleting folders with C++?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Creating, deleting folders with C++?

    Hi!

    I need to be able to create and delete folders from my program. But I can't find out how to do this. For UNIX, and also Linux I suppose, there should be some function like mkdir... But I can't find anything about it. And the home directory, how do I find it?

    Since my program is supposed to work on UNIX, Linux, Windows and MacOS I need to know how to do this on all those operating systems. How is the best way to implement it to compile the right creation function depending on which operating systems the compilation is made on?
    Some kind of macro maybe? Like:
    Qt Code:
    1. #if WIN32
    2. void createWindowsFolder();
    3. #endif
    4.  
    5. #if LINUX
    6. void mkdir
    7. #endif
    8.  
    9. #if MACOS
    10. void mkdir()?
    11. #endif
    To copy to clipboard, switch view to plain text mode 


    thanks for reading
    pir

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating, deleting folders with C++?

    Hi,

    I have to check and grab my code, but I implemented those functions with Qt base IO function.

    1)
    In Qt, you have a mkDir() method in QDir class, or also mkPath().
    So, mkdir is quite easy to do, on every platform ;-)
    You don't have to do all those if...

    2)
    For deleteDir() : simple too !
    You just have to do a recursive method(), that delete all subfolders and files....and then delete current dir.

    I'll look for my old dusty code and keep you in touch

    Guilugi.

  3. #3
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Creating, deleting folders with C++?

    Thanks!
    That seems to be a good way to do it. But I would also like to know how to do this without Qt, because I want to make it easy to change Qt with something else if that is necessary.
    But it is nice to know that I can do it with Qt if I'm getting tired of looking for a solution.

    I found out that getenv() makes it possible to get the home directory for Linux.


    thanks
    pir

  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Creating, deleting folders with C++?

    Quote Originally Posted by pir
    Hi!

    I need to be able to create and delete folders from my program. But I can't find out how to do this. For UNIX, and also Linux I suppose, there should be some function like mkdir... But I can't find anything about it.
    pir
    man 2 mkdir
    man 2 rmdir

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Creating, deleting folders with C++?

    can we create directories through C/C++?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating, deleting folders with C++?

    Quote Originally Posted by sumsin
    can we create directories through C/C++?
    There are POSIX functions for this.

    man 2 mkdir
    man 2 rmdir


  7. #7
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Creating, deleting folders with C++?

    but does POSIX functions will be compatible on WINDOWS.

    as C/C++ are not Operating System dependent.

    ANd Qt also using C++.

    Then is there something in c++ through which we can create folders?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Creating, deleting folders with C++?

    Quote Originally Posted by sumsin
    but does POSIX functions will be compatible on WINDOWS.
    windows implements small part of POSIX, so it might be available.

    http://search.msdn.microsoft.com/sea...siteid=0&tab=0

    Quote Originally Posted by sumsin
    ANd Qt also using C++.
    QDir
    Quote Originally Posted by sumsin
    Then is there something in c++ through which we can create folders?
    No, pure C and C++ can operate only on files. I guess it's part of being "OS independent".

Similar Threads

  1. Problem in creating thread in GUI application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 13:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.