




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include stdio.h#include iostream.h#include string.h#include iomanip.h#define FILENAME_LENGTH 10 /文件名称长度#define COMMAND_LENGTH 10 /命令行长度#define PARA_LENGTH 30 /参数长度 /账号结构 typedef struct users char name8; char pwd10;users; /文件结构struct fnode char filenameFILENAME_LENGTH; int isdir; int isopen; char content255; /我是目录/我是文件 fnode *parent; fnode *child; fnode *prev; fnode *next;/账号users usrarray8 = usr1,usr1, usr2,usr2, usr3,usr3, usr4,usr4, usr5,usr5, usr6,usr6, usr7,usr7, usr8,usr8,; fnode *initfile(char filename,int isdir); void createroot(); int run(); int findpara(char *topara); bool chklogin(char *users, char *pwd); void help(); int mkdir(); int create(); int read(); int write(); int del(); int cd(); int dir();fnode *root,*recent,*temp,*ttemp;char paraPARA_LENGTH,commandCOMMAND_LENGTH,tempparaPARA_LENGTH,recentparaPARA_LENGTH;/创建文件与目录结点 fnode* initfile(char filename,int isdir) fnode *node=new fnode; strcpy(node-filename,filename); node-isdir=isdir; node-isopen=0; node-parent=NULL; node-child=NULL; node-prev=NULL; node-next=NULL; return node;/创建文件存储结点void createroot () recent=root=initfile(/,1); root-parent=NULL; root-child=NULL; root-prev=root-next=NULL; strcpy(para,/); int mkdir() temp=initfile( ,1); cintemp-filename; if(recent-child=NULL) temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL; else ttemp=recent-child; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1) printf(对不起,目录已存在!); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; return 1;int create() temp=initfile( ,0); cintemp-filename; cintemp-content; if(recent-child=NULL) temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL; cout文件建立成功!child; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0) printf(对不起,文件已存在!); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; cout文件建立成功!endl; return 1;int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL) coutTotal: directors i files j child;while(temp) if(temp-isdir) cout filenameendl;i+; else cout filenamenext; coutTotal: directors i files j filename; if(recent-child=NULL) cout文件不存在!child-filename,filename)=0) coutchild-contentchild; while(temp-next) if(strcmp(temp-next-filename,filename)=0) coutnext-contentendl; return 1; cout文件不存在!filename; if(recent-child=NULL) cout文件不存在!child-filename,filename)=0) recent-child-isopen=1;/设置文件标记为打开 cinrecent-child-content; recent-child-isopen=0;/设置文件标记为关闭 cout文件写入成功!child; while(temp-next) if(strcmp(temp-next-filename,filename)=0) recent-child-isopen=1;/设置文件标记为打开 cintemp-next-content; recent-child-isopen=0;/设置文件标记为关闭 cout文件写入成功!endl; return 1; cout文件不存在!topara; if(strcmp(topara,.)=0) int i; while(recent-prev) recent=recent-prev; if(recent-parent) recent=recent-parent; i=strlen(para); while(parai!=/ & i0) i-; if(i!=0) parai=0; else parai+1=0;else findpara(topara); return 1;int findpara(char *topara) int i=0; int sign=1; if(strcmp(topara,/)=0) recent=root; strcpy(para,/); return 1; temp=recent; strcpy(temppara,para); if(topara0=/) recent=root-child; i+; strcpy(para,/); else if(recent!=NULL & recent!=root) strcat(para,/); if(recent & recent-child) if(recent-isdir) recent=recent-child; else printf(路径错误!n); return 1; while(ichild) i+; if(recent-isdir) recent=recent-child; else printf(路径错误n); return 0; strcat(para,/); while(toparai!=/ & ifilename,recentpara)!=0 | (recent-isdir!=1) & recent-next!=NULL) recent=recent-next; if(strcmp(recent-filename,recentpara)=0) if(recent-isdir=0) strcpy(para,temppara); recent=temp; printf(是文件不是目录。n); return 0; strcat(para,recent-filename); if(strcmp(recent-filename,recentpara)!=0 | recent=NULL) strcpy(para,temppara); recent=temp; printf(输入路径错误n); return 0; return 1;int del() char filenameFILENAME_LENGTH; cinfilename; temp=new fnode; if(recent-child) temp=recent-child; while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0) temp=temp-next; if(strcmp(temp-filename,filename)!=0) cout不存在该文件!endl; return 0; else cout不存在该文件!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; delete temp; cout文件已删除!endl; bool chklogin(char *users, char *pwd) int i; for(i=0; i8; i+) if( (strcmp(users,)=0) & (strcmp(pwd,usrarrayi.pwd)=0) return true; return false;void help(void) cout 命 令 一 览 endl; coutendl; coutcreate: 建立文件。 endl; coutread: 读取文件。 endl; coutwrite: 写入文件,支持多线程 endl; coutdel : 删除文件。 endl; coutmkdir: 建立目录。 endl; coutcd: 切换目录。 endl; coutlogout: 退出登录。 endl;int run() coutlinux:para; cincommand; if(strcmp(command,mkdir)=0) mkdir(); else if(strcmp(command,dir)=0) dir(); else if(strcmp(command,cd)=0) cd(); else if(strcmp(command,create)=0) create(); else if(strcmp(command,read)=0) read(); else if(strcmp(command,write)=0) write();else if(strcmp(command,del)=0) del();else if(strcmp(command,help)=0) help(); else if(strcmp(command,logout)=0) return 0; else cout请参考help提供的命令列表!endl; int main()int i=0;bool in=false;char users8,pwd12; cout|-|endl;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 诊所引流现场管理制度
- 诊疗技术授权管理制度
- 调解中心监督管理制度
- 财政特设专户管理制度
- 货代公司各类管理制度
- 货物装卸安全管理制度
- 货船安全生产管理制度
- 2025年中国感应式皂液器行业市场全景分析及前景机遇研判报告
- 2025年中国动作感应手柄行业市场全景分析及前景机遇研判报告
- 液压工具质保协议书范本
- 2025至2030中国材料疲劳试验机行业项目调研及市场前景预测评估报告
- 2025年陕西、山西、宁夏、青海四省(陕晋宁青)高考 生物真题试卷 附答案
- 2024年西昌市教育和体育局考核聘用公立幼儿园教师真题
- 2025设备租赁合同版本范文
- 2025年浙江杭州钱塘区和达能源有限公司招聘笔试冲刺题(带答案解析)
- 2025年衣物清洁多元化发展趋势白皮书-天猫家清第一财经商业数据中心
- 冷链物流园建设项目投融资与财务方案
- 保险业务员分级考试试题及答案
- 2024统编版七年级道德与法治下册期末测试卷(含答案)
- 酒店经销商合同协议书
- 转让钓场合同协议书
评论
0/150
提交评论