delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2008/10/04/20:17:55

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Create folder
Date: Sat, 04 Oct 2008 20:10:26 -0400
Organization: A noiseless patient Spider
Lines: 80
Message-ID: <gc90ls$o10$1@registered.motzarella.org>
References: <48e7fbff$0$18149$4fafbaef AT reader3 DOT news DOT tin DOT it>
Mime-Version: 1.0
X-Trace: feeder.motzarella.org U2FsdGVkX1/mhuXFsbMk2bHgcGDkHfIx+iEiImS6jDE7uxU2htmca8lga/pkakOFCSUy51LA53ZpCh2/HfDTkvbv7dJ1ctiHAs/3ncDhZjLeRs9lTTLomPnbiqYjDRoWaO26NNV5yDI=
X-Complaints-To: Please send complaints to abuse AT motzarella DOT org with full headers
NNTP-Posting-Date: Sun, 5 Oct 2008 00:10:38 +0000 (UTC)
In-Reply-To: <48e7fbff$0$18149$4fafbaef@reader3.news.tin.it>
X-Auth-Sender: U2FsdGVkX1/0fwwXJYTY8cDRaFqc6niP3z7/eQM6krE=
Cancel-Lock: sha1:DqB8gzTMmThwfUaLT7vZpSbeL4o=
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Larsen wrote:
> Hi
> 
> for create a folder internal
> to another folder, as it gets?
> 
> char  string1= {"folder1"};
> 
> _mkdir(string1);

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>

int main(void)
{
     char dirname[] = "./folder1";
     struct stat s;

     if (stat(dirname, &s)) {
         fprintf(stderr, "Good news! stat failed for \"%s\".\n"
                 "We can continue with some safety.\n", dirname);
         perror("Ignore this");
         errno = 0;
     }
     else {
         fprintf(stderr, "Bummer: stat succeeded for \"%s\".\n"
                 "Since it seems to exist already, we can't do this.\n",
                 dirname);
         exit(EXIT_FAILURE);
     }

     if (mkdir(dirname, S_IWUSR)) {
         fprintf(stderr, "mkdir claims to have failed for \"%s\".\n",
                 dirname);
         perror("(mkdir)");
         exit(EXIT_FAILURE);
     }
     else
         fprintf(stderr, "mkdir claims to have succeeded for \"%s\".\n",
                 dirname);

     if (rmdir(dirname)) {
         fprintf(stderr, "rmdir claims to have failed for \"%s\".\n",
                 dirname);
         perror("(rmdir)");
         exit(EXIT_FAILURE);
     }
     else
         fprintf(stderr, "rmdir claims to have succeeded for \"%s\".\n",
                 dirname);


     if (stat(dirname, &s)) {
         fprintf(stderr, "Good news! stat failed for \"%s\".\n"
                 "The directory was removed.\n", dirname);
         perror("Ignore this");
         errno = 0;
     }
     else {
         fprintf(stderr, "Bummer: stat succeeded for \"%s\".\n"
                 "It seems you need to remove it yourself.\n", dirname);
         exit(EXIT_FAILURE);
     }

     return 0;
}


[output]
Good news! stat failed for "./folder1".
We can continue with some safety.
Ignore this: No such file or directory (ENOENT)
mkdir claims to have succeeded for "./folder1".
rmdir claims to have succeeded for "./folder1".
Good news! stat failed for "./folder1".
The directory was removed.
Ignore this: No such file or directory (ENOENT)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019