DALTHTDIR
#include<conio.h>
#include<stdio.h>
#include<io.h>
#include<string.h>
#include<dos.h>
unsigned seg,off;
int dish_num,sh_tep;
char far *p;
char sh_dia,tenthumuc[255];
int sofile=0,sofolder=0;
long unsigned abc=0;
struct structdir{
char dir_name;//khong dung
unsigned char Reserve[20];//khong co tac dung. de cho hop cau truc
unsigned char thuoctinh;
unsigned int file_time;
unsigned int file_date;
unsigned long size_tep;
char ten_tep[13];
}buffer;
void SetDTA(unsigned int buffer);
unsigned char file_first(char *ten_tep,unsigned int thuoctinh);
unsigned char file_next();
void display(struct structdir *buffer,char *tentep,unsigned char thuoctinh);
void get_dir();
void change_dir(char *tenthumuc);
void size_free(char sh_dia);
void mai(struct structdir *buffer)
{
clrscr();
printf("
");
get_dir();
printf("\>DIR ");
//printf("
%c:\\Dir ",sh_dia+65);
gets(tenthumuc);
change_dir(tenthumuc);
printf("
Directory of: ");
get_dir();
printf("
");
Dir(&buffer,"*.*",~0);
size_free(sh_dia);
getch();
}
//Dat vung chuyen du lieu dia
void SetDTA(unsigned int buffer) //disk tranfer address
{
union REGS v;
struct SREGS s;
segread(&s);//Dat noi dung thanh ghi doan vao cau truc s
v.h.ah=0x1A;//Dat DTA
v.x.dx=buffer;
intdosx(&v,&r,&s);
}
//Tim tep dau tien
unsigned char file_first(char *ten_tep,unsigned int thuoctinh)
{
union REGS v;
struct SREGS s;
segread(&s);
v.h.ah=0x4E;
v.x.cx=thuoctinh;
v.x.dx=(unsigned int)ten_tep;
intdosx(&v,&r,&s);
return(!v.x.cflag);
}
//Tim tep ke tiep
unsigned char file_next()
{
union REGS v;
v.h.ah=0x4F;
intdos(&v,&v);
return(!v.x.cflag);
}
//Xuat thong tin len man hinh
void display(struct structdir *buffer)
{
int i;
printf("%0.2d%0.2d%0.4d",(*buffer).file_date&31,(*buffer).file_date>>5&15,((*buffer).file_date>>9)+1980);
if((((*buffer).file_time>>11)&31)<=12)
printf("%0.2d:%0.2d AM",((*buffer).file_time>>11)&31,((*buffer).file_time>>5)&63);
else printf("%0.2d:%0.2d PM",(((*buffer).file_time>>11)&31)-12,(((*buffer).file_time>>5)&63));
if(((*buffer).thuoctinh>>4)&1) printf(" ");
else printf("%7lu ",(*buffer).size_tep);
abc+=(*buffer).size_tep;
for(i=0;(*buffer).ten_tep[i]&&i<15)
printf("%c",(*buffer).ten_tep[i++]));
printf("
");
}
//Lay thong tin tat ca cac file hoac folder trong thu muc hien hanh
void Dir(struct structdir *buffer,char *tentep,unsigned char thuoctinh)
{
SetDTA((unsigned int)&buffer);
if(file_first(tentep,thuoctinh))
{do
{display(&buffer);
++sofile;
}
while(file_next());
}
printf("
%11d File(s) %9lu bytes",sofile-sofoler,abc);
printf("
%ld Folder",sofolder);
}
//lay o dia va thu muc hien hanh
void get_dir()
{
union REGS v,r;
struct SREGS s;
int Odia;
//Lay o dia hien hanh
v.h.ah=0x19;
int86(0x21,&v.&r);
sh_dia=r.h.al;
Odia=r.h.al+65;
//doan lenh lay thu muc hien hanh
dish_num=0;
_DL=dish_num;
_AH=0x47;
geninterrupt(0x21);
seg=_DS;
off=_SI;
p=(char far*)MK_FP(seg,off);
printf("%c:\\%s ",Odia,p);
}
//Chuyen thu muc hien hanh
void change_dir(char *tenthumuc)
{
union REGS v,r;
struct STEGS s;
v.h.ah=0x3B;
v.x.dx=FP_OFF(tenthumuc);
s.ds=FP_SEG(tenthumuc);
int86x(0x21,&v,&r,&s);
}
void size_free(char sh_dia)
{
union REGS v,r;
unsigned long a,b,c,d;
//printf("
O dia hien thoi la %d",sh_dia);
v.h.ah=0x36;
v.h.dl=sh_dia;
int86(0x21,&v,&r);
a=r.x.ax;
b=r.x.bx;
c=r.x.cx;
d=r.x.dx;
//free=b*c*d;
//printf("
Tong so byte: %lu",a*c*d/1024);
printf("%9lu bytes free",b*c*d);
}
Bạn đang đọc truyện trên: Truyen2U.Com