cppannotations/annotations/icmake/removedir

37 lines
761 B
Text

void removeDir(string dir)
{
list parts;
int idx;
int dirIdx;
list entries;
int warn = 1;
if (!exists(dir)) // directory was already removed
return;
parts = findAll("d", dir, ""); // if there are still subdirs
if (listlen(parts) != 0) // then remove at some later stage
return;
chdir(dir);
parts = strtok(dir, "/");
for (idx = listlen(parts); idx--; )
{
entries = backtick("ls -A");
if (listlen(entries) != 0)
{
if (warn)
printf("not removing non-empty dir ", dir, "\n");
return;
}
warn = 0;
chdir("..");
run("rmdir " + parts[idx]);
}
}