Thread: Creating path that its parents not existed

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    7

    Creating path that its parents not existed

    Hi all,

    I want to create a directory that parents doesn't exist. For example i want to create "/etc/dir2/mydir" path. "dir2" directory and "mydir" directory doesn't exist.

    When i use mkdir(path, 0x01FF) function (that path is "/etc/dir2/mydir"), it can't create "mydir" because "dir2" directory doesn't exist.

    How can i solve this problem? I want to create path suddenly same as "mkdir -p /etc/dir2/mydir" command in Linux, i don't want to create path step by step: first dir2 then mydir.

    Please guide me.
    Last edited by pronetin; 11-22-2010 at 04:48 AM.

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    111
    Can't you just run the system (Linux) command from the c program?

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    i don't want to create path step by step:
    Very likely that is what mkdir does...

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Simply loop through the directories and for every seperator create the directory. Eg. for your mkdir, make the following directories:
    Code:
    /etc
    /etc/dir2
    /etc/dir2/mydir
    The ones that exist will fail, and you can check the error code to see if you're still doing okay.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    7
    Very likely that is what mkdir does...
    mkdir doesn't do that. It only try to create last directory("mydir" in my example in first post"). If parent doesn't exist, it will failed.

    Quote Originally Posted by cnewbie1 View Post
    Can't you just run the system (Linux) command from the c program?
    That's Ok.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  3. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  4. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM
  5. reading and creating a file path
    By gjbell21 in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2002, 07:48 PM

Tags for this Thread