Source - Delete Files of Specified Directory (Contains Subdirectory)

xiaoxiao2021-03-06  36

The source code is as follows: / * Project: * Author: Fuweilin Fuweilin@hotmail.com * Date: 2005-1-28 * / #include #include #include #include

#include #define true 1; #define false 0; char * path; / * path * / char * filename; / * file * / void showinfo (void) {textbackground (blue); CLRSCR (); WINDOW (15, 2, 65, 12); TextBackground (YELLOW); CLRSCR (); TextColor (Red); CLRSCR (); CPRINTF ("/ n / n / n"); TextColor (Red); CPRINTF ("/ RAUTHOR: FuWeilin Fuweilin@hotmail.com/n"); CPRINTF ("/ rdate: 2005-1-28 / n / n"); cprintf ("/ RVER: 1.0 build: 0025 / n / N "); TextColor (Black); CPRINTF (" / RFunction: delete a file under the path: / n "); Window (5, 14, 75, 24); TextbackGround (Black); TextColor (White); CLRSCR () Cprintf ("/ Rusage: Delfile path filename. / N / n"); cprintf ("/ rexample: DElfile -d: // abc // def.txt / n / n"); CPrintf ("/ RIT's WILL DELETE All named 'def.txt' file under d: // abc // / n / r "); cprintf (" / r / n / n / n / n / n ");} void usage () {Printf (" / N / R / T / T Delfile / N "); Printf (" Author: FuWeilin Fuweilin@hotmail.com/n "); Printf (" Date: 2005-1- 28 / N "); Printf (" VER: 1.0 / N "); Printf (" FUNTION: DELETE All Files named 'filename' Under the path / n "); Printf (" Usage: Delfile [Path] filename / N " );

} Int Validatearg (int Argc, char * argv []) {

Switch (argc) {casse 2: path = "."; filename = argv [1]; break; case 3: path = argv [1]; filename = argv [2]; break; default: printf ("arg error! Refncence the usage! / n / r "); return 0;} returnit 1;}

INT FINDFILE (PATH, FILE) {char filename [maxdir]; char DIR [MaxDir]; int RTN; Struct Ffblk ff;

/ * Find all dir * /

Strcpy (filename, path); strcat (filename, "//*.*"); RTN = FindFirst (filename, & ff, fa_direc); while (RTN == 0) {

IF ((ff.ff_attrib & 0xf0) == 0x10) && (Strcmp (ff.ff_name, ")) && (Strcmp (ff.ff_name,". ")))) {struct (DIR, PATH); STRCAT (DIR, "//"); STRCAT (DIR, FF.FF_NAME); / * Find INTO SUB DIR * / FINDFILE (DIR, FILE);

} RTN = FINDNEXT (& ff);

/ * Find all file * / strcpy (filename, path); strcat (filename, "//"); strcat (filename, file); RTN = FindFirst (filename, & ff, fa_system | fa_hidden | fa_arch | fa_rdonly); while RTN == 0) {Printf ("% S / /% S / T", PATH, FF.FF_NAME); / * delete the file * / strcpy (dir, path); strcat (dir, "//"); STRCAT (DIR, FF.FF_NAME); IF (unlink (dir)! = 0) Printf ("delete% s failed! / n", dir); Else Printf ("delete% s success! / n", DIR); RTN = FINDNEXT (& FF);

}

Int main (int Argc, char * argv [])

{Int RTN; Char Dir [Maxdir]; Showinfo (); Printf ("/ r / n"); / * usage (); * / if (Validatearg (Argc, Argv) == 0) Return 0; Printf (" Path IS '% S', FileName IS '% S' / N ", PATH, FileName; Findfile (Path, FileName); Printf (" Thank you, 88. ");}

转载请注明原文地址:https://www.9cbs.com/read-62319.html

New Post(0)