操作系統(tǒng)課程設(shè)計(jì)報(bào)告文件管理系統(tǒng)_第1頁(yè)
操作系統(tǒng)課程設(shè)計(jì)報(bào)告文件管理系統(tǒng)_第2頁(yè)
操作系統(tǒng)課程設(shè)計(jì)報(bào)告文件管理系統(tǒng)_第3頁(yè)
操作系統(tǒng)課程設(shè)計(jì)報(bào)告文件管理系統(tǒng)_第4頁(yè)
操作系統(tǒng)課程設(shè)計(jì)報(bào)告文件管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩36頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、 計(jì)算機(jī)科學(xué)與技術(shù)學(xué)院課程設(shè)計(jì)報(bào)告 ( 20008 2009 學(xué)年度 第 一 學(xué)期 )課程名稱(chēng)操作系統(tǒng)課程設(shè)計(jì)項(xiàng)目名稱(chēng)文件管理系統(tǒng)姓名*學(xué)號(hào)*專(zhuān)業(yè)班級(jí)地點(diǎn)教師 一、設(shè)計(jì)任務(wù)及主要技術(shù)本設(shè)計(jì)的目的是通過(guò)設(shè)計(jì)和調(diào)試一個(gè)簡(jiǎn)單的文件系統(tǒng),通過(guò)模擬文件操作命令的執(zhí)行,來(lái)模擬文件管理,使學(xué)生對(duì)主要文件操作命令的實(shí)質(zhì)和執(zhí)行過(guò)程有比較深入的了解,掌握它們的基本實(shí)施方法。具體要求如下:設(shè)計(jì)一個(gè)支持n個(gè)用戶的文件系統(tǒng),每個(gè)用戶可擁有多個(gè)文件;采用二級(jí)或二級(jí)以上的多級(jí)文件目錄管理;對(duì)文件應(yīng)設(shè)置存取控制保護(hù)方式,如“只能執(zhí)行”、“允許讀”、“允許寫(xiě)”等;系統(tǒng)的外部特征應(yīng)接近于真實(shí)系統(tǒng),可設(shè)置下述文件操作命令:建立文件

2、、打開(kāi)文件、關(guān)閉文件、刪除文件、讀文件、寫(xiě)文件、復(fù)制文件、查詢目錄;通過(guò)鍵盤(pán)使用該文件系統(tǒng),系統(tǒng)應(yīng)顯示操作命令的執(zhí)行結(jié)果。二、設(shè)計(jì)方案:主要模仿和實(shí)現(xiàn)windows中”我的電腦”的部分功能系統(tǒng)原理框圖:一、 實(shí)驗(yàn)源碼 :using system;using system.collections.generic;using system.text;using system.io;using system.collections;namespace filediroperate / / 與文件有關(guān)的操作類(lèi) / public class fileoperate / / deletes the fil

3、e. / / 要?jiǎng)h除的文件全路徑 / 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.包括文件的擴(kuò)展名 / / 文件的全路徑 / public string getfilename(strin

4、g filefullpath) if (file.exists(filefullpath) = true) fileinfo f = new fileinfo(filefullpath); return f.name; else return null; / / gets the name of the file. / / 文件的全路徑 / 是否包含文件的擴(kuò)展名 / public string getfilename(string filefullpath, bool includeextension) if (file.exists(filefullpath) = true) fileinf

5、o 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; / / 得到文件的后綴名 / / filein

7、fo / 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(

8、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(fil

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

10、m.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(createfileful

13、lpath); 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(f

14、ilefullpath + .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 = ne

16、w 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; / / 得到文件的創(chuàng)建時(shí)間 / / / public string getfilecre

17、atetime(fileinfo info) return info.creationtime.tostring(); / / 得到文件最后一次修改時(shí)間 / / / public string getfilelastmodifytime(fileinfo info) return info.lastwritetime.tostring(); / / 與文件夾有關(guān)的操作類(lèi) / public class diroperate public enum operateoption / / 存在刪除再創(chuàng)建 / existdelete, / / 存在直接返回 / existreturn / / 創(chuàng)建文件夾

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, tr

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

20、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 dirful

21、lpath, 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) dir

22、ectoryinfo 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(inf

23、o.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, searchpa

24、ttern); return filelist; / / gets the dir files. / / the dir full path. / the search pattern. / the so. / 與當(dāng)前條件匹配的所有文件和文件夾 public string getdirfiles(string dirfullpath, string searchpattern, searchoption so) string filelist = null; if (directory.exists(dirfullpath) = true) filelist = directory.getfi

25、les(dirfullpath, searchpattern, so); return filelist; / / 得到文件的創(chuàng)建時(shí)間 / / 文件的全路徑 / 文件的創(chuàng)建時(shí)間 public string getfilecreatetime(string filefullpath) fileinfo info = new fileinfo(filefullpath); if (info.exists) return info.creationtime.tostring(); else return ; / / 得到文件最后一次修改的時(shí)間 / / 文件的全路徑 / 文件的最后修改時(shí)間 publi

26、c string getfilelastmodifytime(string filefullpath) if(file.exists(filefullpath) return new fileinfo(filefullpath).lastwritetime.tostring(); else return ; / / 得到當(dāng)前目錄下的子目錄或文件 / / 目錄或文件的完整路徑 / 當(dāng)前目錄的所有子目錄和子文件 public filesysteminfo getfilesysteminfo(string filefullpath) if(directory.exists(filefullpath)

27、 directoryinfo info=new directoryinfo(filefullpath); return info.getfilesysteminfos(); else return null; / / 得到文件的創(chuàng)建時(shí)間 / / / public string getdircreationtime(directoryinfo info) return info.creationtime.tostring(); / / 得到文件最后一次修改的時(shí)間 / / / public string getdirlastmodifytime(directoryinfo info) return

28、 info.lastwritetime.tostring(); / / 保存文件夾的大小 / private long length = 0; / / 獲得文件夾的大小 / / 文件夾實(shí)例 / 文件夾大小 public long getdirsize(directoryinfo info) if (info.exists) filesysteminfo infos = info.getfilesysteminfos(); foreach (filesysteminfo inf in infos)/循環(huán)每一個(gè)目錄里的每一個(gè)文件得到總的文件夾的大小 if (inf is directoryinfo) length = +getdirsize(directoryinfo)inf); else length+=(fileinfo)inf).length; /return length; return length; else return 0; / / 循環(huán)得到文件夾的大小 / / 文件夾實(shí)例 / 文件夾的大小 public string getdirsizes(directoryinfo info) long fl = 0; fl+=getdirsize(info); length = 0; if

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論