30 lines
740 B
Text
30 lines
740 B
Text
void create_file(string path) {
|
|
FILE f;
|
|
unless (exists(path)) {
|
|
unless (f = fopen(path, "w")){
|
|
die(path);
|
|
} else {
|
|
puts("file ${path} created");
|
|
fclose(f);
|
|
}
|
|
} else {
|
|
puts("File ${path} already exists");
|
|
}
|
|
}
|
|
|
|
void create_dir(string path) {
|
|
unless (exists(path)) {
|
|
unless(mkdir(path)) { //mkdir returns 0 on success, -1 on error
|
|
puts("directory ${path} created");
|
|
} else {
|
|
puts(stderr, "Error: directory ${path} not created");
|
|
}
|
|
} else {
|
|
puts("directory ${path} already exists");
|
|
}
|
|
}
|
|
|
|
create_file("output.txt");
|
|
create_file("/tmp/output.txt");
|
|
create_dir("docs");
|
|
create_dir("/tmp/docs");
|