论文网首页|会计论文|管理论文|计算机论文|医药学|经济学论文|法学论文|社会学论文|文学论文|教育论文|理学论文|工学论文|艺术论文|哲学论文|文化论文|外语论文|论文格式
中国论文网

用户注册

设为首页

您现在的位置: 中国论文网 >> 工科论文 >> 通信学论文 >> 正文 会员中心
 通信学论文   交通运输论文   工业设计论文   环境工程论文   电力电气论文   水利工程论文   材料工程论文   建筑工程论文   化学工程论文
 机械工程论文   电子信息工程论文   建筑期刊   工科综合论文   汽车制造
通用子目录文件显示方法
在用chkds/v对磁盘子目录及子目录文件进行查找时,由于输出显示信息没有分屏显示,很容易错过需要的信息,并且显示信息没有标记出隐藏的子目录名及子目录文件名,这样就对进一步的子目录及文件操作带来许多不便。若辅以管道操作采用chkdsk/v:|more,虽然可分屏显示,但等待输出时间过长,而且这时^_break中断被封锁,效果不尽人意。本文针对于此采用截获^_break和分屏缓冲输出技术实现子目录和子目录文件及其属性的显示。
一、实现原理
子目录和子目录文件的查找是通过c语言函数findfirst和findnext采用递归算法实现的。
子目录和子目录文件的属性是根据属性字来判断。属性字格式如下图所示:
-----------------
|7|6|5|4|3|2|1|0|
-----------------
第0位(只读位):取1表示只读
第1位(隐含位):取1表示隐含
第2位(系统位):取1表示系统
第3位(卷标位):取1表示卷标
第4位(子目录位):取1表示子目录
第5位(归档位):取1表示归档
第6、7位:保留未用
在子目录及子目录文件查找的递归调用前,保存^_break标记并封锁^_break中断,在正常结束或截获^_break中断(或esc信号)后恢复^_break标记,并恢复指定驱动器的当前子目录、当前驱动器以及当前驱动器的当前子目录。
在子目录和子目录文件的分屏缓冲输出显示方面,建立一输出缓冲区buffer[80*25]来完成结果信息的分屏缓冲输出。wWw.11665.COm
二、程序功能
本程序功能有分屏显示指定驱动器(缺省时为当前驱动器)、指定目录(缺省时为当时目录)中的指定文件(缺省时为*.*)及其所包含的子目录和子目录中的指定文件(缺省时为*.*)。对于子目录显示其子目录名及其属性,对于文件显示匹配的文件名、长度、建立时间及属性,最后输出匹配的文件个数及所包含的子目录个数。在查找过程中可按^_break或esc键退出并返回当前驱动器及其当前目录,若指定驱动器不是当前驱动器则恢复指定驱动器的当前目录。
下面举例说明隐藏子目录的查找。
假定在驱动器a上建立子目录temp,用pctools或 norton工具软件将其属性由10改为ff。这样在dos状态下键入cd temp,系统会提示出错。
作用chkdsk a:,系统提示:
cannot chdir to a:\temp,
tree past this point not processed
使用本程序,运行结果认为temp为一文件,其属性为hsrald,表示这是一个子目录,可据此推猜其为一加密子目录,可进一步用norton工具软件解密。
三、实现实例
实例是在386兼容机、borland c++3.1集成环境和dos 6.0操作系统支持下调试通过,实现源程序附后。
需要指出的不足是,由于findfirst与findnext是通过查找目录项区实现其功能的,所以对一些与fat表不符的隐藏文件及子目录的方法本程序不能奏效,建议结合chkdsk使用本程序。
另外,本文采用的封锁^_break的方法适用于查找过程,但在屏幕输出过程中不能做到封锁^_break中断。若需在查、屏幕输出过程中均封锁^_break中断,可采用ctrbrk函数另建一个^_break中断服务程序。
#include<stdio.h>
#include<stdio.h>
#include<dos.h>
#include<dir.h>
#include<ctype.h>
#include<string.h>
#include<io.h>
#define esc 27
#define ctrl_break 3
#define page_number 22
void dir operate (void);
void add_attrib(struct ffblk);
void full_screen_operate(void);
char driver [maxdrive]="",dir [maxdir]="";
char file [maxfile]="",ext[maxext]=""
char curdriver,curdir [maxdir];
char olddriver,olddir[maxdir],workdir[maxdir];
char fn[13]="*.*";
int page_sum=0,dir_sum=0,file_sum=0;
char buffer[80*25];
char *buffer_pointer=buffer;
char ctrl_bresk_flag;
char attrib[7]="";
main(int argc,char * argv[])
{
curdriver=getdisk();
getcwd(curdir,maxdir);
driver[0]=curdriver+`a';
if(argc>2){
printf("too much parameters!\n");
exit(0)
}
if(argc==2){
fnsplit(argv)[1],driver,dir,file,ext);
if(strcpy(file)!=0){
strcpy(file,exr,13);
strcpy(fn file);
};
if(strlen(driver)!=0){
setdisk(toupper(driver[0])-`a')
setdisk(toupper(drive[0])-`a')
getcwd(olddir,maxdir);
strcpy(workdir,dirver);
if(strlen(dir)!=0)
if(strlen(dir)==1)
strcat(workdir,dir,strlen(dir));
else
strncat(workdir,dir,strlen(dir)-1);
chdir(workdir);
};
}
ctrl_break_flag=getcbrk();
setcbrk(0);
dir_operate()
pust(buffer);
setcbrrk(ctrl_break_flag);
if(dir_sum-1==0)
printf("no sub_directories.\n")
else
printf("%d directories.\n",dir_sum-1)
if(file_sum==0)
printf("no files.\n")
else
printf("%d files.\n",file_sum);
if(strlen(driver)!=0){
chdir(olddir);
};
setdisk(curdriver);
chdir(curdir);
return(0);
}
void dir_operate(void)
{

struct ffblk dirment;
int done,p,byte_num;
unsigned int year,month,date,hour minute;
char path[maxdir];
/*begin to search all possible files*/
done=findfirst(fn,&dirment,0x2f);
getcwd(path,maxpath);
dir_sum++;
page_sum++;
if(page_sum>=page_number)
full_screen_operate();
/*write directory name and its attribute into buffer*/
byte_num=sprintf(buffer_pointer,"directory %s",path);
buffer_poiner+=byte_unm;
byte_unm=sprintf(buffer_pointer,"%6s\n",attrib);
buffer_pointer+=byte_num;
while(!done)
{
page_sum++;
file_sum++;
if(page_sum>=page_number)
full_screen_operate();
/*write filename and its length,time,attribute into buffer*/
bytp_num=sprintf(buffer_pointer,"%20s%
8ld", dor,emt.ff_name,dirment.ff_fsize);
buffer_pointer+=byte_num;
year=(dirment.ff_fdate>>9 &0x7f)+80;
month=dirment.ff_fdate>>5 &0xf;
date=dirment.ff_fdate &0x1f;
hour=dirment.ff_ftime>>11 & 0x1f;
minute=dirment.ff_ftime>>5 & 0x3f;
byte_num=sprintf(bufferr_pointer,"%2d-%
02d-%2d",month,date,year);
buffer_pointer+=byte_num;
if(hour>=12){
byte_num=sprintf(buffer_pointer,"%2d:%02dp",hour-12,minute);
buffer_pointer+=byte_num;
}
else{
byte_num=sprintf(buffer_pointer,"%2d:%2da",hour minute);
buffer_pointer+=byte_num;
}
add_attrib(dirment);
byte_num_sprintf(buffer_pointer,"%6s \n",attrib);
buffer_pointer+=byte_num;
/*continue to search*/
done-findnext(&dirment);
};
/*begin to search all possible directories*/
p=findfirst("*.*",&dirment,0x37);
/*skip directories.and..*/
if(!p &&dirment.ff_name[0]==`.')
{
p=findnext(&dirment);
p=findnext(&dirment);
}
while(!p)
{ /* if it is directory,then operateit*/
if((-chmod(dirment.ff_name,0))&fa_direc)
{
chdir(dirment.ff_name);
add_attrib(dirment);
/*skip directories.and..*/
dir_operate();
chdir("..");
}
/*continue to search*/
p=findnext(&dirment);
}
}
void add_attrib(struct ffblk dirment)
/*calculate attribute of the given file/directory*/
{
if (dirment.ff_attrib & fa_hidden)
attrib[0]=`h';
else
attrib[0]`.';
if(dirment.ff_attrib & fa_system)
attrib[1]=`s';
else
attrib[1]=`.'
if(dirment.ff_attrib & fa_rdonly)
attrib[2]=`r';
else
attrib[2]=".";
if(dirment.ff_attrib & fa_arch)
attrib[3]=`a';
else
attrib[3]=`.';
if(dirment.ff_attrib & fa_label)
attrib[4]=`l';
else
attrib[4]=`.';
if(dirment.ff_attrib &fa_direc)
attrib[5]=`d';
else
attrib[5]=`.';
}
void full_screen_operate(void)
{
char key_value;
/*output full_screen_buffer*/r>puts(buffer);
printf("strike ^_c to terminate or any other key to continue!\n");
asm{
mov ah,7
int 21h
mov key_value,al
}
if(key_value==ctrl_break||key_value==esc){
/*process ctrl_break or esc keyboard input*/
if (strlen(dirver)!=0)}
chdir(olddir);
}
setdisk(curdriver);
chdir(curdir);
setcbrk(ctrl_break_flag);
exit(0);
}
else
printf("searching!......please wait!\n");
buffer_pointer=buffer;
page_sum=0
}
  • 上一篇工学论文:
  • 下一篇工学论文:
  •  作者:王景成 [标签: 通用 目录 文件 显示 方法 ]
    姓 名: *
    E-mail:
    评 分: 1分 2分 3分 4分 5分
    评论内容:
    发表评论请遵守中国各项有关法律法规,评论内容只代表网友个人观点,与本网站立场无关。
    中国(雪野)通用飞机交易中心成立
    固特异携其尖端技术闪亮上海通用技术展【图…
     通用机床加工工艺编制及零件加工 课程一体…
    GSM中通用无线分组业务GPRS的研究(txx26)
    通用变频器的维护及故障诊断方法
    通用报文交换平台的构想与设计
    通用异步收发芯片SCC2691的原理及应用
    简易通用型PCI接口的VHDL
    论美国通用电气公司组织结构及其变革研究
    | 设为首页 | 加入收藏 | 联系我们 | 网站地图 | 手机版 | 论文发表

    Copyright 2006-2013 © 毕业论文网 All rights reserved 

     [中国免费论文网]  版权所有