操作系统课程设计报告----文件管理系统.doc_第1页
操作系统课程设计报告----文件管理系统.doc_第2页
操作系统课程设计报告----文件管理系统.doc_第3页
操作系统课程设计报告----文件管理系统.doc_第4页
操作系统课程设计报告----文件管理系统.doc_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

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

文档简介

计算机科学与技术学院课程设计报告 ( 20008 2009 学年度 第 一 学期 )课程名称操作系统课程设计项目名称文件管理系统姓名*学号*专业班级地点教师 一、设计任务及主要技术本设计的目的是通过设计和调试一个简单的文件系统,通过模拟文件操作命令的执行,来模拟文件管理,使学生对主要文件操作命令的实质和执行过程有比较深入的了解,掌握它们的基本实施方法。具体要求如下:设计一个支持n个用户的文件系统,每个用户可拥有多个文件;采用二级或二级以上的多级文件目录管理;对文件应设置存取控制保护方式,如“只能执行”、“允许读”、“允许写”等;系统的外部特征应接近于真实系统,可设置下述文件操作命令:建立文件、打开文件、关闭文件、删除文件、读文件、写文件、复制文件、查询目录;通过键盘使用该文件系统,系统应显示操作命令的执行结果。二、设计方案:主要模仿和实现windows中”我的电脑”的部分功能系统原理框图:一、 实验源码 :using system;using system.collections.generic;using system.text;using system.io;using system.collections;namespace filediroperate / / 与文件有关的操作类 / public class fileoperate / / deletes the file. / / 要删除的文件全路径 / public bool deletefile(string filefullpath) if (file.exists(filefullpath) = true) file.setattributes(filefullpath, fileattributes.normal); file.delete(filefullpath); return true; else return false; / / gets the name of the file.包括文件的扩展名 / / 文件的全路径 / public string getfilename(string filefullpath) if (file.exists(filefullpath) = true) fileinfo f = new fileinfo(filefullpath); return f.name; else return null; / / gets the name of the file. / / 文件的全路径 / 是否包含文件的扩展名 / public string getfilename(string filefullpath, bool includeextension) if (file.exists(filefullpath) = true) fileinfo f = new fileinfo(filefullpath); if (includeextension = true) return f.name; else return f.name.replace(f.extension, ); else return null; / / 得到文件的大小 / / fileinfo / public string getfilesize(fileinfo info) if (info.exists = true) long fl =info.length; if (fl 1024 * 1024 * 1024) / kb mb gb tb return system.convert.tostring(math.round(fl + 0.00) / (1024 * 1024 * 1024), 2) + gb; else if (fl 1024 * 1024) return system.convert.tostring(math.round(fl + 0.00) / (1024 * 1024), 2) + mb; else return system.convert.tostring(math.round(fl + 0.00) / 1024, 2) + kb; else return null; / / 得到文件的后缀名 / / fileinfo / public string getfileextension(fileinfo info) if (info.exists = true) string extension=info.extension; return extension;/.substring(1); / return extension.substring(1, extension.length - 1); else return null; / / gets the file extension. / / the file full path. / public string getfileextension(string filefullpath) if (file.exists(filefullpath) = true) fileinfo f = new fileinfo(filefullpath); return f.extension; else return null; / / opens the file. / / the file full path. / public bool openfile(string filefullpath) if (file.exists(filefullpath) = true) system.diagnostics.process.start(filefullpath); return true; else return false; / / gets the size of the file. / / the file full path. / public string getfilesize(string filefullpath) if (file.exists(filefullpath) = true) fileinfo f = new fileinfo(filefullpath); long fl = f.length; if (fl 1024 * 1024 * 1024) / kb mb gb tb return system.convert.tostring(math.round(fl + 0.00) / (1024 * 1024 * 1024), 2) + gb; else if (fl 1024 * 1024) return system.convert.tostring(math.round(fl + 0.00) / (1024 * 1024), 2) + mb; else return system.convert.tostring(math.round(fl + 0.00) / 1024, 2) + kb; else return null; / / files to stream byte. / / the file full path. / public byte filetostreambyte(string filefullpath) byte filedata = null; if (file.exists(filefullpath) = true) filestream fs = new filestream(filefullpath, system.io.filemode.open); filedata = new bytefs.length; fs.read(filedata, 0, filedata.length); fs.close(); return filedata; else return null; / / bytes the stream to file. / / the create file full path. / the stream byte. / public bool bytestreamtofile(string createfilefullpath, byte streambyte) try if (file.exists(createfilefullpath) = true) deletefile(createfilefullpath); filestream fs; fs = file.create(createfilefullpath); fs.write(streambyte, 0, streambyte.length); fs.close(); return true; catch return false; / / 序列化xml文件 / / the file full path. / public bool serializexmlfile(string filefullpath) try system.data.dataset ds = new system.data.dataset(); ds.readxml(filefullpath); filestream fs = new filestream(filefullpath + .tmp, filemode.openorcreate); system.runtime.serialization.formatters.binary.binaryformatter ft = new system.runtime.serialization.formatters.binary.binaryformatter(); ft.serialize(fs, ds); fs.close(); deletefile(filefullpath); file.move(filefullpath + .tmp, filefullpath); return true; catch return false; / / 反序列化xml文件 / / the file full path. / public bool deserializexmlfile(string filefullpath) try system.data.dataset ds = new system.data.dataset(); filestream fs = new filestream(filefullpath, filemode.open); system.runtime.serialization.formatters.binary.binaryformatter ft = new system.runtime.serialization.formatters.binary.binaryformatter(); (system.data.dataset)ft.deserialize(fs).writexml(filefullpath + .tmp); fs.close(); deletefile(filefullpath); file.move(filefullpath + .tmp, filefullpath); return true; catch return false; / / 得到文件的创建时间 / / / public string getfilecreatetime(fileinfo info) return info.creationtime.tostring(); / / 得到文件最后一次修改时间 / / / public string getfilelastmodifytime(fileinfo info) return info.lastwritetime.tostring(); / / 与文件夹有关的操作类 / public class diroperate public enum operateoption / / 存在删除再创建 / existdelete, / / 存在直接返回 / existreturn / / 创建文件夹 / / the dir full path. / the dir operate option. / public bool createdir(string dirfullpath, operateoption diroperateoption) try if (directory.exists(dirfullpath) = false) directory.createdirectory(dirfullpath); else if (diroperateoption = operateoption.existdelete) directory.delete(dirfullpath, true); return true; catch return false; / / 删除文件夹 / / the dir full path. / 成功则为true 否则为false public bool deletedir(string dirfullpath) if (directory.exists(dirfullpath) = true) directory.delete(dirfullpath, true); return true; else return false; / / gets the dir files. / / the dir full path. / public string getdirfiles(string dirfullpath) string filelist = null; if (directory.exists(dirfullpath) = true) filelist = directory.getfiles(dirfullpath, *.*, searchoption.topdirectoryonly); return filelist; / / gets the dir files. / / the dir full path. / the so. / public string getdirfiles(string dirfullpath, searchoption so) string filelist = null; if (directory.exists(dirfullpath) = true) filelist = directory.getfiles(dirfullpath, *.*, so); return filelist; arraylist filelist = new arraylist(); public arraylist getdirfiles(string dirfullpath, string pattern) if (directory.exists(dirfullpath) directoryinfo inf = new directoryinfo(dirfullpath); filesysteminfo infos = inf.getfilesysteminfos(); foreach (filesysteminfo info in infos) if (info is fileinfo) if(info.name.contains(pattern) filelist.add(info.fullname); else if (info.name.contains(pattern) filelist.add(info.fullname); getdirfiles(info.fullname, pattern); return filelist; / / gets the dir files. / / the dir full path. / the search pattern. / 所有文件 public string getdirfiles(string dirfullpath, string searchpattern) string filelist = null; if (directory.exists(dirfullpath) = true) filelist = directory.getfiles(dirfullpath, searchpattern); return filelist; / / gets the dir files. / / the dir full path. / the search pattern. / the so. / 与当前条件匹配的所有文件和文件夹 public string getdirfiles(string dirfullpath, string searchpattern, searchoption so) string filelist = null; if (directory.exists(dirfullpath) = true) filelist = directory.getfiles(dirfullpath, searchpattern, so); return filelist; / / 得到文件的创建时间 / / 文件的全路径 / 文件的创建时间 public string getfilecreatetime(string filefullpath) fileinfo info = new fileinfo(filefullpath); if (info.exists) return info.creationtime.tostring(); else return ; / / 得到文件最后一次修改的时间 / / 文件的全路径 / 文件的最后修改时间 public string getfilelastmodifytime(string filefullpath) if(file.exists(filefullpath) return new fileinfo(filefullpath).lastwritetime.tostring(); else return ; / / 得到当前目录下的子目录或文件 / / 目录或文件的完整路径 / 当前目录的所有子目录和子文件 public filesysteminfo getfilesysteminfo(string filefullpath) if(directory.exists(filefullpath) directoryinfo info=new directoryinfo(filefullpath); return info.getfilesysteminfos(); else return null; / / 得到文件的创建时间 / / / public string getdircreationtime(directoryinfo info) return info.creationtime.tostring(); / / 得到文件最后一次修改的时间 / / / public string getdirlastmodifytime(directoryinfo info) return info.lastwritetime.tostring(); / / 保存文件夹的大小 / private long length = 0; / / 获得文件夹的大小 / / 文件夹实例 / 文件夹大小 public long getdirsize(directoryinfo info) if (info.exists) filesysteminfo infos = info.getfilesysteminfos(); foreach (filesysteminfo inf in infos)/循环每一个目录里的每一个文件得到总的文件夹的大小 if (inf is directoryinfo) length = +getdirsize(directoryinfo)inf); else length+=(fileinfo)inf).length; /return length; return length; else return 0; / / 循环得到文件夹的大小 / / 文件夹实例 / 文件夹的大小 public string getdirsizes(directoryinfo info) long fl = 0; fl+=getdirsize(info); length = 0; if

温馨提示

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

评论

0/150

提交评论