int main(int argc, char** argv) { DIR* dp; int arg; char* prog_name; prog_name = argv[0]; if (argc < 2) { usage(prog_name); return 1; } for (arg = 1; arg < argc; arg++) { dp = opendir(argv[arg]); if (dp == NULL) error("%s: Error when opening `%s'", prog_name, argv[arg]); else { int result = emptydir(dp); /* No need to close the directory unless dp wasn't NULL. */ closedir(dp); if (result) printf("`%s' is empty.\n", argv[arg]); else printf("`%s' is not empty.\n", argv[arg]); } } return 0; }
bool f::emptydir(QString sDir, logger* pLog) { QDir src(sDir); QFileInfoList contents = src.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); foreach (QFileInfo fileInfo, contents) { QString fileName = fileInfo.fileName(); QString srcFilePath = src.absoluteFilePath(fileName); if (fileInfo.isDir()) { QDir dstsubdir(srcFilePath); emptydir(srcFilePath, pLog); if(!src.rmdir(fileName)) pLog->wrn("emptydir:!dir.rmdir("+fileName+"):in:'"+sDir+"'"); } else if (fileInfo.isFile()) { if(!QFile::remove(srcFilePath)) pLog->wrn("emptydir:!file.remove:"+srcFilePath); } else { pLog->wrn("emptydir:unexpected:"+srcFilePath); } }
/* * run all user directories, must be bootes (or root on unix) to do this */ void doalldirs(void) { Dir *db; int fd; long i, n; fd = open(".", OREAD); if(fd == -1){ warning("reading %s", root); return; } n = sysdirreadall(fd, &db); if(n > 0){ for(i=0; i<n; i++){ if(db[i].qid.type & QTDIR){ if(emptydir(db[i].name)) continue; switch(forkltd()){ case -1: syslog(0, runqlog, "out of procs"); doload(0); exits(0); case 0: if(sysdetach() < 0) error("%r", 0); dodir(db[i].name); exits(0); default: break; } } } free(db); } close(fd); }