




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、實驗名稱: 文件管理 姓名: 俞家陽 學(xué)號: 1526048 第17頁裝 訂 線【實驗報告正文】一、實驗?zāi)康暮鸵螅ū靥睿嶒災(zāi)康模和ㄟ^在VC平臺下編程,設(shè)計和調(diào)試一個簡單的文件系統(tǒng),通過模擬文件操作命令的執(zhí)行,來模擬文件系統(tǒng)對文件及目錄的管理。實驗要求:兩名學(xué)生成組結(jié)對完成實驗,仿真出文件系統(tǒng)中對文件和目錄的操作。二、實驗內(nèi)容(必填)文件管理:實現(xiàn)一個簡單的文件系統(tǒng)三、實驗原理或?qū)嶒灧椒ǎū靥睿┰恚和ㄟ^結(jié)構(gòu)體來描述文件和目錄,利用鏈表知識實現(xiàn)目錄樹結(jié)構(gòu),通過對鏈表的操作實現(xiàn)整個文件系統(tǒng)中目錄和文件的相關(guān)操作。方法:學(xué)生兩人結(jié)對進(jìn)行實驗,分別實現(xiàn)對文件和目錄的操作。對文件的操作包括:創(chuàng)建文件
2、create、讀文件read、寫文件write、刪除文件delete。對目錄的操作包括:創(chuàng)建目錄mkdir、切換目錄cd、展示目錄內(nèi)容dir、刪除目錄rm。四、主要儀器設(shè)備或?qū)嶒灄l件Windows操作系統(tǒng),VC開發(fā)環(huán)境五、實驗步驟(含實驗數(shù)據(jù)記錄處理)或操作設(shè)計過程記錄#include "stdio.h"#include "iostream.h"#include "string.h"#define FILENAME_LENGTH 10 /文件名稱長度#define COMMAND_LENGTH 10 /命令行長度#define PAT
3、H_LENGTH 30 /參數(shù)長度struct filenode char filenameFILENAME_LENGTH; int isdir; char content255; filenode *parent; filenode *child; filenode *prev; filenode *next;filenode *initnode(char filename,int isdir); void createroot(); int run(); int findpath(char *topath); void help(); int mkdir(); int create();
4、int read(); int write(); int del(); int rm(); int cd(); int dir();filenode *root,*recent,*temp,*ttemp,*temp_child;char pathPATH_LENGTH,commandCOMMAND_LENGTH,temppathPATH_LENGTH,recentpathPATH_LENGTH;/創(chuàng)建文件或目錄的存儲節(jié)點filenode* initnode(char filename,int isdir) filenode *node=new filenode; strcpy(node->
5、;filename,filename); node->isdir=isdir;node->parent=NULL; node->child=NULL; node->prev=NULL;node->next=NULL;return node;/初始化文件系統(tǒng)根結(jié)點void createroot () recent=root=initnode("/",1); root->parent=NULL; root->child=NULL; root->prev=root->next=NULL; strcpy(path,"/
6、"); void help() cout<<endl; cout<<"create: 建立文件。 "<<endl; cout<<"read: 讀取文件。 "<<endl; cout<<"write: 寫入文件。 "<<endl; cout<<"delete: 刪除文件。 "<<endl; cout<<"rm: 刪除目錄。 "<<endl; cout<
7、<"mkdir: 建立目錄。 "<<endl; cout<<"cd: 切換目錄。 "<<endl; cout<<"dir: 顯示目錄。 "<<endl; cout<<"logout: 退出登錄。 "<<endl;int dir()int i=0,j=0;temp=new filenode;temp=recent;if(temp=root)cout<<" <DIR> "<<
8、"."<<endl; if(temp!=root)cout<<" <DIR> "<<"."<<endl;i+;if(temp->child=NULL) cout<<"Total: "<<" directors " <<i<<" files "<< j <<endl; return 1;temp=temp->child;while(te
9、mp) if(temp->isdir) cout<<" <DIR> "<<temp->filename<<endl;i+; else cout<<" <FILE> "<<temp->filename<<endl;j+; temp=temp->next; cout<<"Total: "<<" directors " <<i<<" files
10、"<< j <<endl;return 0;int read()char filenameFILENAME_LENGTH;cin>>filename; if(recent->child=NULL) cout<<"文件不存在!"<<endl; return 1; if(strcmp(recent->child->filename,filename)=0) cout<<recent->child->content<<endl; return 0; else
11、 temp=recent->child; while(temp->next) if(strcmp(temp->next->filename,filename)=0) cout<<temp->next->content<<endl; return 0; cout<<"文件不存在!"<<endl; return 1; int write()char filenameFILENAME_LENGTH;cin>>filename; if(recent->child=NULL) cou
12、t<<"文件不存在!"<<endl; return 1; if(strcmp(recent->child->filename,filename)=0) cin>>recent->child->content; cout<<"文件寫入成功!"<<endl; return 0; else temp=recent->child; while(temp->next) if(strcmp(temp->next->filename,filename)=0) c
13、in>>temp->next->content; cout<<"文件寫入成功!"<<endl; return 0; cout<<"文件不存在!"<<endl; return 1; int del() char filenameFILENAME_LENGTH; cin>>filename; temp=new filenode; if(recent->child) temp=recent->child; while(temp->next &&
14、 (strcmp(temp->filename,filename)!=0 | temp->isdir!=0) temp=temp->next; if(strcmp(temp->filename,filename)!=0 | temp->isdir!=0) cout<<"不存在該文件!"<<endl; return 0; else cout<<"不存在該文件!"<<endl; return 0; if(temp->parent=NULL) temp->prev->
15、;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; return 0;int rm() char fil
16、enameFILENAME_LENGTH; cin>>filename; temp=new filenode; if(recent->child) temp=recent->child; while(temp->next && (strcmp(temp->filename,filename)!=0 | temp->isdir!=1) temp=temp->next; if(strcmp(temp->filename,filename)!=0 | temp->isdir!=1) cout<<"不存在
17、該目錄!"<<endl; return 0; else cout<<"不存在該目錄!"<<endl; return 0; if(temp->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-
18、>parent; temp->parent->child=temp->next; delete temp; cout<<"目錄已刪除!"<<endl; return 0;int cd() char topathPATH_LENGTH; cin>>topath; if(strcmp(topath,".")=0) return 0; if(strcmp(topath,".")=0) int i; while(recent->prev)recent=recent->pr
19、ev; /向前回溯,找到第一次創(chuàng)建的目錄if(recent->parent) recent=recent->parent; i=strlen(path);/ printf("%d %sn",i,path); while(pathi!='/' && i>0) i-; /找到最右邊的/if(i!=0) pathi='0' /printf("%s",path); /path中不止有一個/else pathi+1='0' elsefindpath(topath); return 0
20、;int findpath(char *topath) unsigned int i=0; int sign=1; if(strcmp(topath,"/")=0) /如果命令是cd / recent=root; strcpy(path,"/"); return 0; temp=recent; strcpy(temppath,path); if(topath0='/') /cd命令以cd /開始 recent=root->child; i+; strcpy(path,"/");/printf("n%s&
21、quot;,path); else if(recent!=NULL && recent!=root) strcat(path,"/");/ printf("n%sn",path); if(recent && recent->child)if(recent->isdir) recent=recent->child;elseprintf("路徑錯誤!n");return 1; while(i<=strlen(topath) && recent) int j=0; if
22、(topathi='/' && recent->child) i+; if(recent->isdir) recent=recent->child; else printf("路徑錯誤n"); return 1; strcat(path,"/"); while(topathi!='/' && i<=strlen(topath) recentpathj=topathi; i+;j+; recentpathj='0' while(strcmp(recent
23、->filename,recentpath)!=0 | (recent->isdir!=1) && recent->next!=NULL) recent=recent->next; if(strcmp(recent->filename,recentpath)=0) if(recent->isdir=0) strcpy(path,temppath); recent=temp; printf("是文件不是目錄。n"); return 1; strcat(path,recent->filename); if(strcmp(
24、recent->filename,recentpath)!=0 | recent=NULL) strcpy(path,temppath); recent=temp; printf("輸入路徑錯誤n"); return 1; return 0;int mkdir() temp=initnode(" ",1); cin>>temp->filename;if(recent->child=NULL) temp->parent=recent; temp->child=NULL; recent->child=temp;
25、 temp->prev=temp->next=NULL;printf("目錄建立成功!n"); else ttemp=recent->child;if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=1) printf("目錄已存在!n"); return 1; while(ttemp->next) ttemp=ttemp->next; if(strcmp(ttemp->filename,temp->filename)
26、=0&&ttemp->isdir=1) printf("目錄已存在!n"); return 1; ttemp->next=temp; temp->parent=NULL; temp->child=NULL; temp->prev=ttemp; temp->next=NULL; printf("目錄建立成功!n"); return 0;int create() temp=initnode(" ",0); cin>>temp->filename; if(recent-&
27、gt;child=NULL) temp->parent=recent; temp->child=NULL; recent->child=temp; temp->prev=temp->next=NULL; cout<<"文件創(chuàng)建成功!"<<endl; else ttemp=recent->child; if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=0) printf("文件已存在!n"); re
28、turn 1; while(ttemp->next) ttemp=ttemp->next; if(strcmp(ttemp->filename,temp->filename)=0&&ttemp->isdir=0) printf("文件已存在!n"); return 1; ttemp->next=temp; temp->parent=NULL; temp->child=NULL; temp->prev=ttemp; temp->next=NULL; cout<<"文件建立成功!"<<endl; return 0;int run() cout<<"filesystem:"<<path<<">
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- T/CCS 044-2023掘進(jìn)工作面遠(yuǎn)程控制系統(tǒng)技術(shù)規(guī)范
- T/CMSTA 002-2024公路零擔(dān)專線物流服務(wù)規(guī)范
- T/CI 514-2024富水砂層盾構(gòu)隧道變形監(jiān)測與安全控制技術(shù)規(guī)范
- 不老泉測試題及答案
- T/CCOA 73-2023菜籽油感官評價
- 2025年機(jī)動車抵押合同2篇
- 【8語期末】蚌埠市經(jīng)開區(qū)2023-2024學(xué)年八年級下學(xué)期期末教學(xué)質(zhì)量監(jiān)測語文試卷
- 污水處理系統(tǒng)設(shè)計方案
- 健康促進(jìn)校培訓(xùn)課件
- 有見證人婚前房產(chǎn)協(xié)議書6篇
- 通信原理ch9-1-抽樣課件
- 工程經(jīng)濟(jì)學(xué)項目經(jīng)濟(jì)評價案例分析
- 最全深圳市工改工案例分析
- 信托行業(yè)信息化系統(tǒng)技術(shù)白皮書
- 在市財政系統(tǒng)警示教育暨作風(fēng)建設(shè)大會上的講話
- 《管理信息系統(tǒng)》課程設(shè)計報告范文
- GB∕T 37821-2019 廢塑料再生利用技術(shù)規(guī)范
- 測量學(xué)地形圖的基本知識培訓(xùn)講義PPT(講解)
- 自控實驗三線性定常系統(tǒng)的穩(wěn)態(tài)誤差
- 特種設(shè)備作業(yè)人員考試中心質(zhì)量管理手冊(共31頁)
- COC文件審核清單
評論
0/150
提交評論