Like Tree1Likes
  • 1 Post By Bayint Naung

create new folder based on argv[]... not working

This is a discussion on create new folder based on argv[]... not working within the C Programming forums, part of the General Programming Boards category; im trying to create a new folder to store other folders containing data that has the same name of an ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    12

    create new folder based on argv[]... not working

    im trying to create a new folder to store other folders containing data that has the same name of an input string to main.

    Code:
    sprintf(file_name, "/cygdrive/c/Dev-Cpp/%s", argv[1]);
    file = fopen(file_name, "rb");     //open the .fti file
    if (file == NULL) {
    		printf("Unable to open .fti file.\n\n");
    ignore the fact that im opening a file contained within dev-cpp directory but running netbeans lol. I fopen a file based on an input in the command prompt. I then want to use this in the following code to create a directory of folders that is contained within a folder that has the name of the original input in the command prompt... i hope its clear.

    Code:
        sprintf(new_folder, "/cygdrive/c/Netbeans/Mnemosine/output/%s/%s",argv[1], fti_parameter);
        mkdir(new_folder, "S_IRWXU" );
    anyway i can create the folders but i cannot create the single folder that contains these folders.. the program runs without errors but no folder is created. can people check my code and see if there are errors or mistakes and provide help.. thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
           int mkdir(const char *path, mode_t mode);
    mkdir() don't want string as 2nd argument. and check return value.
    Salem likes this.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,442
    > mkdir(new_folder, "S_IRWXU" );
    Are you getting any compiler warnings for trying to pass a string as the 2nd parameter here?

    Also, mkdir() does NOT create hierarchies. You have to make each new nested subdir directly
    Code:
        sprintf(new_folder, "/cygdrive/c/Netbeans/Mnemosine/output/%s",argv[1]);
        mkdir(new_folder, S_IRWXU);
        sprintf(new_folder, "/cygdrive/c/Netbeans/Mnemosine/output/%s/%s",argv[1], fti_parameter);
        mkdir(new_folder, S_IRWXU );
    Also, mkdir() returns a success/fail, and updates errno - it might be a good idea to check these as well, before posting "it doesn't work".
    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.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    firstly i apologise... i know i should spend more time checking details myself instead of asking these questions. I am short on time and only started learning C a few months ago so i am trying to learn and do a lot in a short space of time for a project, so i am using these boards as a timesaver (at the moment, soon i will be finished and have time to learn properly for myself instead of for the project)... i know its not ideal.

    thanks for the information, you are right. I also did get warnings like you said

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Don't be afraid to experiment.

    (great advice, in my humble opinion)
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. API Call to create folder
    By cboard_member in forum Windows Programming
    Replies: 2
    Last Post: 12-01-2005, 11:08 AM
  2. Create folder from variable name
    By nmullane in forum C++ Programming
    Replies: 4
    Last Post: 09-25-2005, 06:41 AM
  3. How to create a folder
    By andreas_nordman in forum C++ Programming
    Replies: 1
    Last Post: 06-14-2004, 06:25 AM
  4. How to write programt to create folder?
    By ooosawaddee3 in forum C++ Programming
    Replies: 3
    Last Post: 03-25-2003, 08:03 AM
  5. Create folder
    By toby1909 in forum Windows Programming
    Replies: 1
    Last Post: 01-29-2002, 12:57 AM

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