DALTHTDIR1

Màu nền
Font chữ
Font size
Chiều cao dòng

#include <conio.h>

#include <stdio.h>

#include <dos.h>

#include <io.h>

#include <string.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; /* Kich thuoc file*/

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) ;

void Dir(struct structdir *buffer,char *tentep,unsigned char thuoctinh) ;

void get_dir() ;

void change_dir(char *tenthumuc) ;

void size_free(char sh_dia) ;

// chuong trinh chinh

void main(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); // tac dung cua dau ~ la mo luon thu muc ... va in la DIR neu la thu muc

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 ;// dat data 2byte cua thongtin_tep vao thanh DX

intdosx(&v, &v, &s);

}

// tim tep dau tien

unsigned char file_first( char *ten_tep, unsigned int thuoctinh)

{ union REGS v;

struct SREGS s;

segread(&s); // dat noi dung thanh ghi doan vao cau truc s tuong duong s.ds = FP_SEG(TEN);v.x.dx = FP_OF(ten)

v.h.ah = 0x4E;

v.x.cx = thuoctinh;

v.x.dx = (unsigned int) ten_tep;

intdosx(&v,&v,&s);

return(!v.x.cflag);

}

// tim tep ke tiep

unsigned char file_next() // tim tep

{ union REGS v;

v.h.ah = 0x4F;

intdos(&v, &v);

return(!v.x.cflag);// co nho CF = 1 la bi loi ,AX chua ma loi

}

// xuat thong tin len mang 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(" <DIR> ");++sofolder;}

else printf(" ");

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-sofolder,abc) ;

printf("

%11d 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 SREGS 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.Net