操作系统课程设计报告文件管理系统.doc

上传人:文库蛋蛋多 文档编号:3796620 上传时间:2023-03-22 格式:DOC 页数:41 大小:2.20MB
返回 下载 相关 举报
操作系统课程设计报告文件管理系统.doc_第1页
第1页 / 共41页
操作系统课程设计报告文件管理系统.doc_第2页
第2页 / 共41页
操作系统课程设计报告文件管理系统.doc_第3页
第3页 / 共41页
操作系统课程设计报告文件管理系统.doc_第4页
第4页 / 共41页
操作系统课程设计报告文件管理系统.doc_第5页
第5页 / 共41页
点击查看更多>>
资源描述

《操作系统课程设计报告文件管理系统.doc》由会员分享,可在线阅读,更多相关《操作系统课程设计报告文件管理系统.doc(41页珍藏版)》请在三一办公上搜索。

1、 计算机科学与技术学院课程设计报告 ( 20008 2009 学年度 第 一 学期 )课程名称操作系统课程设计项目名称文件管理系统姓名*学号*专业班级地点教师一、设计任务及主要技术本设计的目的是通过设计和调试一个简单的文件系统,通过模拟文件操作命令的执行,来模拟文件管理,使学生对主要文件操作命令的实质和执行过程有比较深入的了解,掌握它们的基本实施方法。具体要求如下:设计一个支持n个用户的文件系统,每个用户可拥有多个文件;采用二级或二级以上的多级文件目录管理;对文件应设置存取控制保护方式,如“只能执行”、“允许读”、“允许写”等;系统的外部特征应接近于真实系统,可设置下述文件操作命令:建立文件、

2、打开文件、关闭文件、删除文件、读文件、写文件、复制文件、查询目录;通过键盘使用该文件系统,系统应显示操作命令的执行结果。二、设计方案:主要模仿和实现Windows中”我的电脑”的部分功能系统原理框图:一、 实验源码 :using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Collections;namespace FileDirOperate / / 与文件有关的操作类 / public class FileOperate / / Deletes the file

3、. / / 要删除的文件全路径 / 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

4、 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

5、 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

6、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; / / 得到文件的后缀名 / / FileInf

7、o / 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(s

8、tring 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(File

9、FullPath); 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

10、.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. / /

11、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;

12、 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(CreateFileFull

13、Path); 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(Fi

14、leFullPath + .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;

15、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

16、 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 getFileCrea

17、teTime(FileInfo info) return info.CreationTime.ToString(); / / 得到文件最后一次修改时间 / / / public String getFileLastModifyTime(FileInfo info) return info.LastWriteTime.ToString(); / / 与文件夹有关的操作类 / public class DirOperate public enum OperateOption / / 存在删除再创建 / ExistDelete, / / 存在直接返回 / ExistReturn / / 创建文件夹

18、/ / 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, tru

19、e); 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 s

20、tring 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 DirFull

21、Path, 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) Dire

22、ctoryInfo 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

23、.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. / return

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号