A small script to show all the Directories and Files in a specified Drive or Directory. It shows all the files and folders in a tree style with the file size, last modified date and other file attributes.
It is just like the dir /p command of the Windows Command line or ls command in Unix.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #include<stdio.h> #include<conio.h> #include<process.h> # include <dir.h> #include<ctype.h> # include <io.h> #include<string.h> # include <dos.h> union f { int a[2]; struct ftime b; }c; int getdiskno(char a[]) { if(a[1]==':') return(tolower(a[0])-'a'+1); return (getdisk()+1); } long int ret(int a) { struct dfree b; getdfree(a,&b); return (long int)((long int)(b.df_avail)*(long int)(b.df_sclus)*(long int)(b.df_bsec)); } int countdig(long int a) { int count=0; if(a==0)return 1; while(a!=0) { a=a/10; count++; } return count; } main(int argc,char *argv[]) { int count=0,mode=0,i; long int totsize=0; struct ffblk a; char string[15]; if(argc>=2) strcpy(string,argv[1]); else strcpy(string,"*.*"); if(argc>=3) { if(strcmp(argv[2],"r")==0) mode=FA_RDONLY; if(strcmp(argv[2],"h")==0) mode=FA_HIDDEN; if(strcmp(argv[2],"d")==0) mode=FA_DIREC; if(strcmp(argv[2],"s")==0) mode=FA_SYSTEM; if(strcmp(argv[2],"a")==0) mode=FA_ARCH; if(strcmp(argv[2],"l")==0) mode=FA_LABEL; } //clrscr(); if(findfirst(string,&a,mode)!=0) { printf("\nCould not find a file to match your criterion\n"); exit(0); } count++; printf("\nListing files...\n"); totsize+=a.ff_fsize; printf("\n%s",a.ff_name); for(i=0;i<(15-strlen(a.ff_name));i++) printf(" "); printf("%ld",a.ff_fsize); c.a[0]=a.ff_ftime; c.a[1]=a.ff_fdate; for(i=0;i<(10-countdig(a.ff_fsize));i++) printf(" "); if(c.b.ft_day<10)printf("0"); printf("%u-",c.b.ft_day); if(c.b.ft_month<10)printf("0"); printf("%u-%u",c.b.ft_month,c.b.ft_year+1980); printf(" "); if(c.b.ft_hour<10)printf("0"); printf("%u:",c.b.ft_hour); if(c.b.ft_min<10)printf("0"); printf("%u:",c.b.ft_min); if(c.b.ft_tsec<10)printf("0"); printf("%u",c.b.ft_tsec); while(findnext(&a)==0) { count++; printf("\n%s",a.ff_name); totsize+=a.ff_fsize; for(i=0;i<(15-strlen(a.ff_name));i++) printf(" "); printf("%ld",a.ff_fsize); c.a[0]=a.ff_ftime; c.a[1]=a.ff_fdate; for(i=0;i<(10-countdig(a.ff_fsize));i++) printf(" "); if(c.b.ft_day<10)printf("0"); printf("%u-",c.b.ft_day); if(c.b.ft_month<10)printf("0"); printf("%u-%u",c.b.ft_month,c.b.ft_year+1980); printf(" "); if(c.b.ft_hour<10)printf("0"); printf("%u:",c.b.ft_hour); if(c.b.ft_min<10)printf("0"); printf("%u:",c.b.ft_min); if(c.b.ft_tsec<10)printf("0"); printf("%u",c.b.ft_tsec); if(count%20==0) { if(count!=20)printf("\n"); printf("\n\nListed %d files",count); printf("\nPress a key for next page...."); getch(); clrscr(); } } printf("\n\nListed %d files\n%ld bytes in all\n",count,totsize); printf("\n%ld bytes available in drive %c:",ret(getdiskno(string)),'a'+getdiskno(string)-1); return 0; } |