1、文件管理华中师范大学计算机科学系操作系统实验报告实验题目:文件管理 学生姓名: 学生学号: 日期:2011-12-18 实验 4 文件管理【实验目的】1)了解磁盘的物理组织。 2)掌握windows系统提供的有关对磁盘操作的函数。 3)根据输入的扇区号读/写指定扇区。【实验准备知识】需要了解已经学过的VC+工程文件的运行步骤以及它的操作界面常用的设置方法。【实验内容】在已做过的实验五、六的基础上编写一个程序,分别完成如下功能。1) 有个help帮助提示。2) 查看位示图。3) 在目录文件中创建子目录。4) 根据当前目录切换到指定目录。5) 搜索所要删除的目录是否为空目录,若是则删除。6) 在当
2、前目录中创建文件名称。7) 搜索所要删除的文件是否存在,若是则删除。8) 列出当前目录的所有目录项,退出程序等。实验要求: 深入理解操作系统设备当作文件处理的特性。参考源代码:/ wjgl.cpp: implementation of the wjgl class./#include wjgl.h/ Construction/Destruction/wjgl:wjgl() hang=16; lie=16; int j,k; /cout矩阵的行hang; /cout矩阵的列lie; srand(time(NULL); for(j=0;jlie;j+) juzhen0j=1; for(j=1;jh
3、ang;j+) for(k=0;klie;k+) juzhenjk=(rand()%2); cout当前没有任何目录和文件,系统为你自动进入C:,如需帮助请选择Hname,C); ml-awenjian=NULL; ml-top=NULL; ml-next=NULL; ml-amulu=NULL;wjgl:wjgl()int wjgl:cd() node1 *s; node1 *r; r=(node1 *)malloc(sizeof(node1); s=(node1 *)malloc(sizeof(node1); s=ml; r=zhizhen; char mlname20; cinmlnam
4、e; if(!strcmp(mlname,.) if(zhizhen-top=NULL) cout不存在该目录的根目录top; / showweizhi(); return 0; else r=r-amulu; while(r!=NULL) if(!strcmp(r-name,mlname) zhizhen=r; /showweizhi(); return 0; else if(r-next=NULL) break; r=r-next; cout目录不存在awenjian; node *s1; s1=(node *)malloc(sizeof(node); /cout请输入文件的名称fname
5、; /cout请输入文件的大小daxiao; strcpy(s1-name,fname); s1-daxiao=daxiao; s1-next=NULL; if(s=NULL) zhizhen-awenjian=s1; s1-time=tmpbuf; / cout文件创建成功name,fname) cout文件名字重复next!=NULL) if(!strcmp(s-next-name,fname) cout文件名字重复next; s-next=s1; int i,j,k; k=0; int i1=-1; int j1=-1; for(i=0;ihang;i+) for(j=0;jbegin=
6、i*lie+j+1; if(daxiao=1) juzhenij=-1; s1-time=tmpbuf; return 0; else i1=i; j1=j; k+; continue; else if(daxiao-k=1) juzheni1j1=i*lie+j+1; juzhenij=-1; s1-time=tmpbuf; return 0; juzheni1j1=i*lie+j+1; i1=i; j1=j; k+; s1-next=NULL; s1-time=tmpbuf; return 0;void wjgl:showweizhi() cout.setf(3); char dizhi2
7、010; int i=0; int j; node1 *s; node1 *r; r=(node1 *)malloc(sizeof(node1); s=(node1 *)malloc(sizeof(node1); r=zhizhen; s=r-top; strcpy(dizhii,r-name); i+; /coutname; while(s!=NULL) strcpy(dizhii,s-name); /coutname; s=s-top; i+; for(j=i;j0;j-) coutdizhij-1; if(i=j) cout:; else cout; cout;int wjgl:rd()
8、 showweizhi(); node1 *r; r=(node1 *)malloc(sizeof(node1); r=zhizhen-amulu; cout输入要删除的目录的名字ming; if(r=NULL) cout目录不存在name,ming) if(r-amulu!=NULL|r-awenjian!=NULL) cout目录不空不能删除amulu=r-next; /cout删除成功next!=NULL) if(!strcmp(r-next-name,ming) if(r-next-amulu!=NULL|r-next-awenjian!=NULL) cout目录不空不能删除next=
9、r-next-next; /cout删除成功endl; return 0; cout目录不存在amulu; char ming20; cinming; if(r=NULL) node1 *s; s=(node1 *)malloc(sizeof(node1); s-time=tmpbuf; strcpy(s-name,ming); s-awenjian=NULL; s-amulu=NULL; s-next=NULL; s-top=zhizhen; zhizhen-amulu=s; else if(!strcmp(r-name,ming) cout目录已经存在next!=NULL) if(!str
10、cmp(r-next-name,ming) cout目录已经存在next; node1 *s; s=(node1 *)malloc(sizeof(node1); s-time=tmpbuf; strcpy(s-name,ming); s-awenjian=NULL; s-amulu=NULL; s-next=NULL; s-top=zhizhen; r-next=s; / cout创建成功awenjian;/ cout请输入文件的名称ming; int i,j; int temp; if(s=NULL) cout删除不成功name,ming) i=(s-begin-1)/lie; j=(s-b
11、egin-1)%lie; while(juzhenij!=-1) temp=juzhenij; juzhenij=0; i=(temp-1)/lie; j=(temp-1)%lie; juzhenij=0; zhizhen-awenjian=s-next; cout删除成功next!=NULL) if(!strcmp(s-next-name,ming) i=(s-begin-1)/lie; j=(s-begin-1)%lie; while(juzhenij!=-1) temp=juzhenij; juzhenij=0; i=(temp-1)/lie; j=(temp-1)%lie; juzhe
12、nij=0; s-next=s-next-next; / cout删除成功endl; return 0; cout文件不存在不能删除endl; return 0;void wjgl:tree() char c=getchar(); if(c= ) jiansuo(); else shuchu(zhizhen);void wjgl:showweishitu() /cout.width(); int j,k; cout位示图为endl; for(j=0;jhang;j+) for(k=0;klie;k+) coutsetiosflags(ios_base:left)setw(4)juzhenjk;
13、 coutamulu; cout . ; showweizhi(); couttop; if(zhizhen=NULL) ; else cout . ; showweizhi(); coutendl; zhizhen=r1; while(r!=NULL) i+; couttime name next; node *s; s=(node *)malloc(sizeof(node); s=sc-awenjian; while(s!=NULL) j+; k=k+s-daxiao; couttime name 大小 daxiao next; cout当前共有目录i个endl; cout当前共有文件j个
14、 总大小为:kendl; int count=0; for(j=0;jhang;j+) for(k=0;klie;k+) if(juzhenjk=0) count+; cout剩余countendl;void wjgl:jiansuo() int k=0; int i=0; int j=0; char name20;/ cout请输入名称name; int temp1=strlen(name); mulu *r; r=(node1 *)malloc(sizeof(node1); r=zhizhen-amulu; node *s; s=(node *)malloc(sizeof(node); s
15、=zhizhen-awenjian; while(r!=NULL) if(panduan(name,r-name)=1) i+; couttime name ; showweizhi(); coutnext; while(s!=NULL) if(panduan(name,s-name)=1) j+; couttime name 大小 daxiao daxiao; showweizhi(); coutnext; cout目录i个endl; cout文件j个 总大小为kendl; int count=0; for(j=0;jhang;j+) for(k=0;klie;k+) if(juzhenjk
16、=0) count+; cout剩余countendl;int wjgl:panduan(char a, char b) int biaoji=0; if(!strcmp(a,b) return 1; int temp=strlen(a); int temp1=strlen(b); int i,j; for(i=0,j=0;itemp&jtemp1) return 0; return 1;*/#include#includewjgl.husing namespace std;void menu() coutH-helpendl; coutS -查看位示图endl; coutMD-在目录文件中创
17、建子目录endl; coutCD-根据当前目录切换到指定目录endl; coutRD-搜索所要删除的目录是否为空目录,若是则删除endl; coutMK-在当前目录中创建文件名称endl; coutDEL-搜索所要删除的文件是否存在,若是则删除endl; coutDIR-列出当前目录的所有目录项endl; coutE-退出程序endl;int main() wjgl awjgl; /menu(); while(1) awjgl.showweizhi(); /cout请选择操作xuanxiang; if(!strcmp(xuanxiang,H)|!strcmp(xuanxiang,h) menu(); if(!strcmp(xuanxiang,MD)|!strcmp(xuanxiang,md) awjgl.md()
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1