永恒の翼 |
2005-01-29 22:50 |
最后一个更可怕,好管用,删除当前盘下的指定名称的文件,不论属性,自动历遍目录树,仅未测试隐藏目录,估计有效。
请注意不要使用通配符,否则后果自负
代码 | #include <stdio.h> #include <stdlib.h> #include <dos.h> #include <dir.h> #include <string.h> struct ffblk f,ff; int i,j,node,done; char dir[100][MAXDIR],file[50]; char mid[MAXDIR],curr[MAXDIR]; repeat(); delpro(); int main(int argc,char *argv[]) /*main program*/ { if (argc!=2) { printf ("\n Warning:\n"); printf ("\t This program will NOT prompt you to choice YES or NO,\n"); printf ("\t you must decide to delete the file(s).\n\n"); printf ("Usage: delall <filename> \n"); printf ("\t This program supports * and ? \n"); exit (0); } strcpy (file,argv[1]); strupr (file); getcwd (curr,MAXDIR); i=1;j=0; system ("cd\\"); getcwd (dir[i],MAXDIR); printf ("Now browsing %s in the Directory(ies)...\n",file); repeat(); } repeat() /*browse the directory*/ { getcwd (mid,MAXDIR); delpro(); done=findfirst("*.*",&ff,FA_DIREC|FA_SYSTEM|FA_HIDDEN|FA_ARCH|FA_RDONLY); while (!done) { if (((ff.ff_attrib & 0xf0)==16) && strcmp(ff.ff_name,".") && strcmp(ff.ff_name,"..")) { i=i+1; if (strlen(mid)==3) { strcpy (dir[i],mid); strcat (dir[i],ff.ff_name); } else { strcpy (dir[i],mid); strcat (dir[i],"\\"); strcat (dir[i],ff.ff_name); } } done=findnext(&ff); } if (i==1) { chdir (curr); if (j==0) printf ("Can not find the file(s)!\n"); else printf ("Deleted %d file(s).",j); exit (0); } chdir (dir[i]); i--; repeat(); } delpro() /*delete function*/ { node=findfirst(file,&f,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH); while (!node) { unlink (f.ff_name); j=j+1; printf ("Deleting %s, The Directory is %s .\n",f.ff_name,mid); node=findnext(&f); } }
|
|
|