操作技巧系统试验模拟文件管理方案计划系统_第1页
操作技巧系统试验模拟文件管理方案计划系统_第2页
操作技巧系统试验模拟文件管理方案计划系统_第3页
操作技巧系统试验模拟文件管理方案计划系统_第4页
操作技巧系统试验模拟文件管理方案计划系统_第5页
免费预览已结束,剩余12页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、:【实验报告正文】:一、实验目的和要求(必填);实验目的:通过在VC平台下编程,设计和调试一个简单的文件系统,通过模拟文件操作命:令的执行,来模拟文件系统对文件及目录的管理。;实验要求:两名学生成组结对完成实验,仿真出文件系统中对文件和目录的操作。;二、实验内容(必填)F;文件管理:实现一个简单的文件系统j三、实验原理或实验方法(必填)装原理:通过结构体来描述文件和目录,利用链表知识实现目录树结构,通过对链表的操作实、现整个文件系统中目录和文件的相关操作。方法:学生两人结对进行实验,分别实现对文件和目录的操作。线对文件的操作包括:创建文件create读文件read、写文件write删除文件de

2、lete;对目录的操作包括:创建目录mkdir、切换目录cd、展示目录内容dir、删除目录rm。;四、主要仪器设备或实验条件:Windows操作系统,VC开发环境:五、实验步骤(含实验数据记录处理)或操作设计过程记录#include"stdio.h"p#include"iostream.h"#include"string.h"far:#defineFILENAME_LENGTH10/文件名称长度:#defineCOMMAND_LENGTH10/命令行长度j#definePATH_LENGTH30/参数长度structfilenodec

3、harfilenameFILENAME_LENGTH;intisdir;charcontent255;filenode*parent;filenode*child;filenode*prev;filenode*next;filenode*initnode(charfilename,intisdir);voidcreateroot();intrun();intfindpath(char*topath);voidhelp();intmkdir();intcreate();intread();intwrite();intdel();intrm();intcd();intdir();filenode*

4、root,*recent,*temp,*ttemp,*temp_child;charpathPATH_LENGTH,commandCOMMAND_LENGTH,temppathPATH_LENGTH,recentpathPATH_LENGTH;/创建文件或目录的存储节点filenode*initnode(charfilename,intisdir)(filenode*node=newfilenode;strcpy(node->filename,filename);node->isdir=isdir;node->parent=NULL;node->child=NULL;n

5、ode->prev=NULL;node->next=NULL;returnnode;/初始化文件系统根结点voidcreateroot()recent=root=initnode("/",1);root->parent=NULL;root->child=NULL;root->prev=root->next=NULL;strcpy(path,"/");voidhelp()cout<<endl;cout<<"create:建立又件。"<<endl;cout<&l

6、t;"read:读取文件。"<<endl;cout<<"write:写入文件。"<<endl;cout<<"delete:删除文件。"<<endl;cout<<"rm:删除目录。"<<endl;cout<<"mkdir:建立目录。"<<endl;cout<<"cd:切换目录。"<<endl;cout<<"dir:显示目录。&

7、quot;<<endl;cout<<"logout:退出登录"<<endl;intdir()(inti=0,j=0;temp=newfilenode;temp=recent;if(temp=root)cout<<"<DIR>if(temp!=root)cout<<"<DIR>if(temp->child=NULL)cout<<"Total:"<<"directorsreturn1;)temp=temp->c

8、hild;while(temp)if(temp->isdir)cout<<"<DIR>elsecout<<"<FILE>temp=temp->next;)cout<<"Total:"<<"directorsreturn0;)<<"."<<endl;<<"."<<endl;i+;<<i<<"files"<<j<<

9、;endl;"<<temp->filename<<endl;i+;"<<temp->filename<<endl;j+;<<i<<"files"<<j<<endl;intread()charfilenameFILENAME_LENGTH;cin>>filename;if(recent->child=NULL)(cout<<”文件不存在!"<<endl;return1;if(strcmp(recen

10、t->child->filename,filename)=0)(cout<<recent->child->content<<endl;return0;else(temp=recent->child;while(temp->next)(if(strcmp(temp->next->filename,filename)=0)(cout<<temp->next->content<<endl;return0;cout<<”文件不存在!"<<endl;return1

11、;intwrite()charfilenameFILENAME_LENGTH;cin>>filename;if(recent->child=NULL)(cout<<”文件不存在!"<<endl;return1;if(strcmp(recent->child->filename,filename)=0)(cin>>recent->child->content;cout<<”文件写入成功!"<<endl;return0;else(temp=recent->child;wh

12、ile(temp->next)(if(strcmp(temp->next->filename,filename)=0)(cin>>temp->next->content;cout<<”文件写入成功!"<<endl;return0;cout<<”文件不存在!"<<endl;return1;intdel()(charfilenameFILENAME_LENGTH;cin>>filename;temp=newfilenode;if(recent->child)(temp=r

13、ecent->child;while(temp->next&&(strcmp(temp->filename,filename)!=0|temp->isdir!=0)temp=temp->next;if(strcmp(temp->filename,filename)!=0|temp->isdir!=0)(cout<<"不存在该文件!"<<endl;return0;else(cout<<"不存在该文件!"<<endl;return0;if(temp-&g

14、t;parent=NULL)(temp->prev->next=temp->next;if(temp->next)temp->next->prev=temp->prev;temp->prev=temp->next=NULL;else(if(temp->next)temp->next->parent=temp->parent;temp->parent->child=temp->next;)deletetemp;cout<<"文件已删除!"<<endl;ret

15、urn0;)intrm()(charfilenameFILENAME_LENGTH;cin>>filename;temp=newfilenode;if(recent->child)(temp=recent->child;while(temp->next&&(strcmp(temp->filename,filename)!=0|temp->isdir!=1)temp=temp->next;if(strcmp(temp->filename,filename)!=0|temp->isdir!=1)(cout<<&

16、quot;不存在该目录!"<<endl;return0;)else(cout<<"不存在该目录!"<<endl;return0;)if(temp->parent=NULL)(temp->prev->next=temp->next;if(temp->next)temp->next->prev=temp->prev;temp->prev=temp->next=NULL;)else(if(temp->next)temp->next->parent=temp-

17、>parent;temp->parent->child=temp->next;)deletetemp;cout<<"目录已删除!"<<endl;return0;)intcd()chartopathPATH_LENGTH;cin>>topath;if(strcmp(topath,".")=0)return0;if(strcmp(topath,".")=0)inti;while(recent->prev)recent=recent->prev;/向前回溯,找到第一次创

18、建的目录if(recent->parent)(recent=recent->parent;)i=strlen(path);/printf("%d%sn",i,path);while(pathi!='/'&&i>0)i-;/找到最右边的/if(i!=0)pathi='0'/printf("%s",path);/path中不止有一个/)elsepathi+1='0')elsefindpath(topath);)return0;)intfindpath(char*topath)u

19、nsignedinti=0;intsign=1;if(strcmp(topath,"/")=0)/如果命令是cd/recent=root;strcpy(path,"/");return0;)temp=recent;strcpy(temppath,path);if(topath0='/')/cd命令以cd/开始(recent=root->child;i+;strcpy(path,"/");/printf("n%s",path);)else(if(recent!=NULL&&rec

20、ent!=root)(strcat(path,"/");/printf("n%sn",path);)if(recent&&recent->child)(if(recent->isdir)recent=recent->child;else(printf("路径错误!n");return1;)while(i<=strlen(topath)&&recent)(intj=0;if(topathi='/'&&recent->child)(i+;if(r

21、ecent->isdir)recent=recent->child;elseprintf("路径错误n");return1;)strcat(path,"/");)while(topathi!='/'&&i<=strlen(topath)recentpathj=topathi;i+;j+;)recentpathj='0'|(recent->isdir!=1)&&while(strcmp(recent->filename,recentpath)!=0recent-&

22、gt;next!=NULL)recent=recent->next;)if(strcmp(recent->filename,recentpath)=0)if(recent->isdir=0)strcpy(path,temppath);recent=temp;printf("是文件不是目录。n");return1;)strcat(path,recent->filename);)if(strcmp(recent->filename,recentpath)!=0|recent=NULL)strcpy(path,temppath);recent=tem

23、p;printf("输入路径错误n");return1;)return0;)intmkdir()temp=initnode("”,1);cin>>temp->filename;if(recent->child=NULL)temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;printf("目录建立成功!n");)elsettemp=recent->child;if(strcm

24、p(ttemp->filename,temp->filename)=0&&ttemp->isdir=1)(printf("目录已存在!n");return1;while(ttemp->next)(ttemp=ttemp->next;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=1)(printf("目录已存在!n");return1;ttemp->next=temp;temp->parent=N

25、ULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;printf("目录建立成功!n");return0;intcreate()(temp=initnode("",0);cin>>temp->filename;if(recent->child=NULL)(temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;cout&

26、lt;<”文件创建成功!"<<endl;else(ttemp=recent->child;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=0)(printf("文件已存在!n");return1;while(ttemp->next)(ttemp=ttemp->next;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=0)(printf("文件已存在!n");return1;ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;cout<<"文件建立成功!"<<endl;return0;intrun()cout<<"filesystem:"<<

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论