home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
ms_dos
/
ftree
/
ftree.c
next >
Wrap
Text File
|
1990-06-14
|
4KB
|
179 lines
/* FTREE.C V1.0 L10 by MSどす */
/* for MS-C V5.1 1989.09.25 */
/* last update 1989.09.29 */
#include <stdio.h>
#include <dos.h>
#include <string.h>
#define BMAX 512
#define SPC_AREA " - - - - - - - - - - - - - - - - - - - - - - - - - - "
/*
struct FIND_TAG{
char reserved[21];
char attrib;
unsigned wr_time;
unsigned wr_date;
long size;
char name[13];
} f_buf;
*/
struct find_t f_buf;
struct FTAG{
char attrib;
unsigned wr_time;
unsigned wr_date;
long size;
char name[13];
} f_inf[BMAX];
long total=0;
int cnt=0;
unsigned short nesting=0,proc_flg=0;
char outbuf[256];
void ftree(char *path_name){
int i,start;
unsigned ret;
char p_work[80],s_work[32];
strcpy(p_work,path_name);
strcat(p_work,"\\*.*");
s_work[0]=0;
for(i=0;i<nesting;i++){
strcat(s_work,"| ");
}
strcat(s_work,"+--");
nesting ++;
if(nesting > 8){
strcpy(outbuf,"(ERROR: ディレクトリが深すぎます。表示できません。)");
puts(outbuf); /* TOWNS */
return;
}
/* SET DTA */
ret= _dos_findfirst(p_work,0x3f,&f_buf);
/* 正常 */
start=cnt;
while(ret==0 && cnt<BMAX){ /* ファイル検索 */
f_inf[cnt].attrib = f_buf.attrib; /* *fbuf. */
f_inf[cnt].wr_time = f_buf.wr_time;
f_inf[cnt].wr_date = f_buf.wr_date;
f_inf[cnt].size = f_buf.size;
strncpy(f_inf[cnt].name ,f_buf.name ,13);
cnt ++;
ret= _dos_findnext(&f_buf);
}
for(i=start;proc_flg==0 && i<cnt;i++){ /* ファイル一覧 */
if(f_inf[i].attrib != 0x10){
/* NOT SUB-DIR */
/* strcpy(outbuf,s_work);
strncat(outbuf, f_inf[i].name ,13);*/
sprintf(outbuf,"%s%-13s",s_work,f_inf[i].name);
strcat(outbuf,SPC_AREA);
sprintf(&outbuf[36],"%c%c%c%c%c %04u.%02u.%02u %02u:%02u %8ld"
,(f_inf[i].attrib & 0x20)? 'a' : '.'
/* ,(f_inf[i].attrib & 0x10)? 'd' : '.' */
,(f_inf[i].attrib & 0x08)? 'v' : '.'
,(f_inf[i].attrib & 0x04)? 's' : '.'
,(f_inf[i].attrib & 0x02)? 'h' : '.'
,(f_inf[i].attrib & 0x01)? 'o' : 'w'
,((f_inf[i].wr_date >>9 ) & 0x7f) + 1980
,(f_inf[i].wr_date >>5 ) & 0xf
,(f_inf[i].wr_date ) & 0x1f
,(f_inf[i].wr_time >>11) & 0x1f
,(f_inf[i].wr_time >>5 ) & 0x3f
,f_inf[i].size);
puts(outbuf); /* TOWNS */
}
}
total=0; /* 容量計算する */
for(i=start;i<cnt;i++){
if(f_inf[i].attrib != 0x10){
total += (f_inf[i].size); /* OVER-FLOW大丈夫かな... */
}
}
strcpy(outbuf,s_work); /* 容量表示する */
/* outbuf[strlen(s_work)-3] = 0;*/
strcat(outbuf," ");
strcat(outbuf,SPC_AREA);
sprintf(&outbuf[42],"ファイル容量 計(約%5uKB)",(total + 512)/1024);
puts(outbuf); /* TOWNS */
for(i=start;i<cnt;i++){ /* サブディレクトリ一覧 */
if((f_inf[i].attrib == 0x10) && (f_inf[i].name[0] != '.')){
/* IS SUB-DIR */
strcpy(outbuf,s_work);
strncat(outbuf,f_inf[i].name,13);
/* EGBで文字パターン変更 */
puts(outbuf);
/* EGBで文字パターン変更 */
strcpy(p_work,path_name);
strcat(p_work,"\\");
strncat(p_work,f_inf[i].name,13);
ftree(p_work);
}
}
cnt = start;
nesting --;
}
char drive_name[]="?:";
void main(int argc,char *argv[]){
unsigned drv;
short int i;
struct diskfree_t f;
if(argc > 3){
puts("help : FTREE -?");
return;
}
proc_flg=0;
for(i=1;i<argc;i++){
if(argv[i][0] == '/' || argv[i][0] == '-'){
if(toupper(argv[i][1]) == 'D'){
proc_flg=1; /* DIRECTORY ONLY */
}
else{
puts("使用方法:FTREE ドライブ [/D]");
puts(" /D 指定時にはディレクトリ名のみ表示します。");
return;
}
}
else{
drive_name[0] = toupper(argv[i][0]);
}
}
if(drive_name[0] == '?'){
_dos_getdrive(&drv);
drive_name[0] = 'A' + drv -1;
}
else{
drv = drive_name[0] +1 - 'A';
}
cnt = 0;
puts("[FTREE V1.0 L10 by MSどす] アトリビュート ファイル日付 サイズ(バイト)");
sprintf(outbuf,"%s\\",drive_name);
puts(outbuf); /* TOWNS */
ftree(drive_name);
puts("~");
_dos_getdiskfree(drv,&f);
sprintf(outbuf,"%dKB 使用可能です。",f.bytes_per_sector / 1024
* f.avail_clusters * f.sectors_per_cluster);
puts(outbuf); /* TOWNS */
puts("正常終了しました");
}