1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
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]);
}
}
|