File: removedir

package info (click to toggle)
c++-annotations 11.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 11,244 kB
  • sloc: cpp: 21,698; makefile: 1,505; ansic: 165; sh: 121; perl: 90
file content (37 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (4)
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]);
    }
}