A small script to show all the Directories and Files in a specified Drive or Directory. It shows all the files/folders in a tree with the file size, last modified and other file attributes.
It is just like the DIR/P command of the DOS.

[sourcecode language=’cpp’]

/*******************************************************
* MYCPLUS Sample Code – http://www.mycplus.com *
* *
* This code is made available as a service to our *
* visitors and is provided strictly for the *
* purpose of illustration. *
* *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/

/*
Muhammad Saqib
Please change BGI directory accouding to your TC Directory
By default it is “E:\tc\bgi”
*/

#include
#include
#include

# include
#include
# include
#include
# include

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; }[/sourcecode]

2 Shares
Share2
+1
Tweet
Share
Stumble