文件管理系统.docx
- 文档编号:5881872
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:25
- 大小:76.95KB
文件管理系统.docx
《文件管理系统.docx》由会员分享,可在线阅读,更多相关《文件管理系统.docx(25页珍藏版)》请在冰豆网上搜索。
文件管理系统
计算机操作系统
课程设计说明书
(题目)
文件管理系统
起止日期:
2009年12月31日至2009年1月7日
学生姓名
班级
学号
成绩
指导教师(签字)
机电信息部(部)
2010年1月7日
目录
1课程设计简介1
1.1课程设计的目的1
1.2课程设计内容1
2数据结构的设计2
3功能模块(或算法)描述3
4程序运行结果4
5心得体会5
参考文献6
附源代码7
1课程设计简介
1.1课程设计的目的
设计和调试一个简单的文件系统,通过模拟文件操作命令的执行,来模拟文件管理,对主要文件操作命令的实质和执行过程有比较深入的了解,掌握它们的基本实施方法.
1.2课程设计内容
1.设计采用多级文件目录,用户可拥有多个文件。
2.设计一个较实用的用户界面,方便用户使用,界面要为用户提供足够的选择信息。
3.采用二级或二级以上的多级文件目录管理。
2数据结构
改变目录:
cd<目录名>,工作目录转移到指定的目录下。
目录不存在时,给出错误信息。
创建文件:
create<文件名>,创建一个指定名字的新文件,即在目录中增加一项,不考虑文件的内容。
对于重名文件给出错误信息。
删除文件:
delete<文件名>,当没在用户使用指定文件时,将其删除。
文件不存在时给出错误信息。
显示目录:
dir<目录名>,显示指定目录下的全部文件和第一级子目录,如果没有指定目录名,则显示当前目录下的相应内容。
创建目录:
create<目录名>,在指定路径下创建指定的目录,如没有指定路径,则在当前目录下创建指定的目录。
对于重名目录给出错误信息。
删除目录:
delete<目录名>,删除指定目录及其下的全部文件和子目录。
如果指定目录为空,可直接删除,否则给出用户提示是否删除。
关闭目录:
close<目录名>,关闭指定目录及其下的全部文件和子目录。
打开目录:
open<目录名>,打开指定目录。
重命名:
renameXXXYYY重命名指定目录
其他说明:
<目录名>和<文件名>都支持全路径名和相对路径名。
文件名由目录结构中各级文件名分量排列构成,各分量间用“/”隔开。
输入exit命令可退出此模拟文件管理系统。
3功能模块(或算法)描述
//显示时间
voidshow_time(SYSTEMTIME&sys)
//显示当前目录中的所有文件和文件夹
voiddir(vector
//登陆信息
intlogin()
//在当前目录中创建文件或文件夹
voidcreate(vector
//在当前目录中删除文件或文件夹
voiddel(vector
//关闭当前目录中的文件
voidclose(vector
//显示出错信息
voiderror()
//判断当前目录中指定名称的文件是否存在
boolfind_file(vector
//判断当前目录中指定名称的文件夹是否存在
boolfind_file_server(vector
//给当前目录中的文件或文件夹重命名
voidrename(vector
//打开当前目录中的文件
voidopen(vector
5心得体会
实验中主要问题及故障现象的分析及设计结论:
结构体的设计和运用很不熟练,结构体数组的运用,结构体的每个元素都是独立的一个
模块,但都统一被结构体变量所调用,结构体数组是一个逻辑数组。
编程体会和心得:
一个程序要有灵感,但这个灵感是你在前一百个想法都失败的情况下的第一百零一个想法,如果有了灵感就不要停下来尽可能的都花时间来写程序,这样慢慢你的灵感就会越来越多。
附源代码
#include
#include
#include
#include
#include
#include
#definePASSWD"admin"
#include
usingnamespacestd;
typedefstructFCB
{
stringFileName;//文件名
stringFileType;//文件类型
vector
vector
stringparent;//父文件夹名
SYSTEMTIMEcreating_time;//创建时间
SYSTEMTIMElast_modified_time;//最近访问时间
stringstatus;//文件状态
}FCB;
//显示时间
voidshow_time(SYSTEMTIME&sys)
{
cout< "< "< } //显示当前目录中的所有文件和文件夹 voiddir(vector { intlength=a.size(); inti=0; for(i=1;i { cout< if(a[i].FileType! ="") { cout<<"."< cout<<"创建时间: "; show_time(a[i].creating_time); cout<<"最近访问时间: "; show_time(a[i].last_modified_time); cout<<"状态: "; cout< } else { cout<<"创建时间: "; show_time(a[i].creating_time); cout<<"最近访问时间: "; show_time(a[i].last_modified_time); cout<<"状态: "; cout< } } } //登陆信息 intlogin() { intnumber=0; //ceshi charpwd[32]; inti=0; while(i++<3){ printf("*********************************************************\n"); printf("请输入文件系统访问密码: "); scanf("%s",pwd); if(strcmp(pwd,PASSWD)==0){ number=1; printf("登陆成功欢迎访问! \n"); printf("*********************************************************\n"); break; } } if(i==4){ printf("Sorry! \n"); } returnnumber; // } //显示帮助信息 voidhelp() {system("cls"); printf("*********************************************************\n"); printf("文件管理系统\n"); printf("指导老师: 文志诚\n"); printf("本组组员,梁植程,吴楠,刘佳乐,何侃,陈周,毛伟\n"); printf("*********************************************************\n"); cout<<"dir"<<"显示当前目录中的所有文件和文件夹"< cout<<"help"<<"显示帮助信息"< cout<<"命令+? "<<"显示该命令的说明文档,如: dir? "< cout<<"createxxx"<<"在当前目录中创建文件xxx.yyy或文件夹xxx"< cout<<"deletexxx"<<"在当前目录中删除文件xxx.yyy或文件夹xxx"< cout<<"openxxx"<<"打开当前目录中的文件xxx.yyy或文件夹xxx"< cout<<"closexxx"<<"关闭当前目录中的文件xxx.yyy或文件夹xxx"< cout<<"cd/"<<"返回到上一级目录"< cout<<"cdxxx"<<"转到当前目录的xxx子目录"< cout<<"cdroot"<<"转到根目录root"< cout<<"renamexxxyyy"<<"重命名"< cout<<"exit"<<"退出"< } //判断是否是帮助请求命令 boolis_require(string&str) { return(str[str.length()-1]=='? '); } //显示命令的说明 voidcommand_explan(string&command) { if(command=="dir? ")cout<<"\"dir\"命令用于显示当前目录中的所有文件和文件夹"< elseif(command=="help? ")cout<<"\"help\"命令用于显示帮助信息"< elseif(command=="create? ")cout<<"\"create\"命令用于在当前目录中创建文件或文件夹,如: createhello.txt,createhello,注意: 创建文件必须有扩展名,无扩展名则认为是文件夹,文件和文件不能同名,文件夹和文件夹不能同名,文件和文件夹可以同名"< elseif(command=="delete? ")cout<<"\"delete\"命令用于在当前目录中删除文件或文件夹,如: deletehello.txt,deletehello"< elseif(command=="open? ")cout<<"\"open\"命令用于在当前目录中打开文件或文件夹,如: openhello.txt,openhello"< elseif(command=="close? ")cout<<"\"close\"命令用于在当前目录中关闭文件或文件夹,如: closehello.txt,closehello"< elseif(command=="cd? ")cout<<"\"cd\"命令用于跳转目录,如: cdhello,\"cd/\"用于跳转到当前目录的上一级目录,\"cdroot\"用于直接转到根目录"< elseif(command=="rename? ")cout<<"\"rename\"命令用于给当前目录中的文件或文件夹重命名,如: renamehello.txthi.cpp(可以修改扩展名),renamehello.txthi(不加扩展名则默认为原扩展名),renamehellohi(修改文件夹名)"< elseif(command=="exit? ")cout<<"\"exit\"命令用于退出系统"< elsecout<<"nosuchcommand! "< } //在当前目录中创建文件或文件夹 voidcreate(vector { stringfile="",name="",type=""; FCBfcb,fcb2; intlength=0,i=0; intsize=(*a).size(); cin>>file; length=file.length(); for(i=0;i { if(file[i]=='.')break; } if(i { name=file.substr(0,i); type=file.substr(i+1,length-i-1); for(i=1;i { if((*a)[i].FileName==name&&(*a)[i].FileType! ="") { cout<<"Thefilenamehasbeenexisted! "< return; } } fcb.FileName=name; fcb.FileType=type; fcb.subdirectory=NULL; fcb.updirectory=NULL; fcb.parent=""; GetLocalTime(&fcb.creating_time); GetLocalTime(&fcb.last_modified_time); fcb.status="closed"; (*a).push_back(fcb); } else { name=file.substr(0,i); for(i=1;i { if((*a)[i].FileName==name&&(*a)[i].FileType=="") { cout<<"Thefilenamehasbeenexisted! "< return; } } vector fcb2.FileName=""; fcb2.FileType=""; fcb2.subdirectory=NULL; fcb2.updirectory=a; fcb2.parent=name; GetLocalTime(&fcb2.creating_time); GetLocalTime(&fcb2.last_modified_time); fcb2.status="closed"; fcb.FileName=name; fcb.FileType=""; fcb.subdirectory=sub_dir; fcb.updirectory=NULL; fcb.parent=""; GetLocalTime(&fcb.creating_time); GetLocalTime(&fcb.last_modified_time); fcb.status="closed"; (*a).push_back(fcb); (*sub_dir).push_back(fcb2); } } //在当前目录中删除文件或文件夹 voiddel(vector { stringfile="",filename="",filetype=""; cin>>file; intlength=file.length(); intsize=a.size(); inti=0; for(i=0;i { if(file[i]=='.')break; } if(i { filename=file.substr(0,i); filetype=file.substr(i+1,length-i-1); for(i=1;i { if(a[i].FileName==filename&&a[i].FileType! ="") { if(a[i].FileType==filetype) { a.erase(&a[i]); cout< } elsecout<<"nosuchfile"< return; } } if(i==size)cout<<"nosuchfile"< } elseif(i==length) { for(i=1;i { if(a[i].FileName==file&&a[i].FileType=="") { a.erase(&a[i]); cout< return; } } if(i==size)cout<<"nosuchfile"< } elsecout<<"nosuchfile"< } //打开当前目录中的文件 voidopen(vector { stringfile="",filename="",filetype=""; cin>>file; intlength=file.length(); intsize=a.size(); inti=0; for(i=0;i { if(file[i]=='.')break; } if(i { filename=file.substr(0,i); filetype=file.substr(i+1,length-i-1); for(i=1;i { if(a[i].FileName==filename&&a[i].FileType! ="") { if(a[i].FileType==filetype) { if(a[i].status=="closed") { a[i].status="opened"; GetLocalTime(&a[i].last_modified_time); cout< return; } else { cout< return; } } elsecout<<"nosuchfile"< return; } } if(i==size)cout<<"nosuchfile"< return; } elseif(i==length) { for(i=1;i { if(a[i].FileName==file&&a[i].FileType=="") { if(a[i].status=="closed") { a[i].status="opened"; GetLocalTime(&a[i].last_modified_time); cout< return; } else {
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 文件 管理 系统