Created
March 29, 2012 10:22
-
-
Save PhDP/2235676 to your computer and use it in GitHub Desktop.
Creating files/folders with system calls to mkdir in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang folders.c -o folders | |
// Creating folders with system calls to mkdir | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main() | |
{ | |
const int layer1 = 5; | |
const int layer2 = 10; | |
const int outfiles = 100; | |
char buffer[100]; | |
int i = 0; | |
for (; i < layer1; ++i) | |
{ | |
sprintf(buffer, "mkdir folder%d", i); | |
system(buffer); | |
int j = 0; | |
for (; j < layer2; ++j) | |
{ | |
sprintf(buffer, "mkdir folder%d/xyz%d", i, j); | |
system(buffer); | |
int k = 0; | |
for (; k < outfiles; ++k) | |
{ | |
sprintf(buffer, "folder%d/xyz%d/fichier%d.xml", i, j, k); | |
FILE *out = fopen(buffer, "w"); | |
fprintf(out, "<xml>\n <i>%d</i>\n <j>%d</j>\n <k>%d</k>\n</xml>", i, j, k); | |
fclose(out); | |
} | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment