模擬文件管理系統(tǒng)_第1頁
模擬文件管理系統(tǒng)_第2頁
模擬文件管理系統(tǒng)_第3頁
模擬文件管理系統(tǒng)_第4頁
模擬文件管理系統(tǒng)_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

操作系統(tǒng)課程設計工程三實驗報告姓名:學號:學院:專業(yè):指導教師:2014年*月*日工程三:文件系統(tǒng)一、教學內容模擬文件管理。設計并調試一個簡單的文件系統(tǒng),模擬文件操作命令的執(zhí)行。深入了解主要文件操作命令的執(zhí)行過程,掌握它們的根本實施方法。1.實現(xiàn)文件系統(tǒng)的根本功能設計一個支持n個用戶的文件系統(tǒng),每個用戶可擁有多個文件。采用二級或二級以上的多級文件目錄管理。對文件設置存取控制保護方式,如“只能執(zhí)行”、“允許讀”、“允許寫”等。系統(tǒng)的外部特征應接近于真實系統(tǒng),可以設置下述文件操作命令:建立文件、翻開文件、關閉文件、刪除文件、讀文件、寫文件、復制文件、查詢目錄。通過鍵盤使用該文件系統(tǒng),系統(tǒng)應當顯示操作命令的執(zhí)行結果。二、源程序與注釋#include<stdio.h>//#include<string.h>#include<windows.h>#include<sys/stat.h>//文件屬性#include<io.h>//文件常用庫#include<direct.h>//創(chuàng)立刪除目錄voidmean(){printf("\t\t**********文件管理系統(tǒng)************\n");printf("\t\t1.創(chuàng)立目錄\n");printf("\t\t2.刪除目錄\n");printf("\t\t3.創(chuàng)立文件\n");printf("\t\t4.設置權限\n");printf("\t\t5.寫入文件\n");printf("\t\t6.讀取文件\n");printf("\t\t7.刪除文件\n");printf("\t\t8.復制文件\n");printf("\t\t9.翻開文件\n");printf("\t\t10.退出\n");printf("\t\t**********************************\n");}voidcreatecatalog(){inta;charname[10],choice;label:printf("請輸入路徑和目錄名字例:C:/a\n");scanf("%s",name);getchar();a=mkdir(name);if(a==-1){printf("文件夾名相同\n");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{printf("目錄創(chuàng)立成功");printf("\n");}}voiddeletecatalog(){inta;charname[10],choice;label:printf("請輸入要刪除的目錄路徑和名字例:C:/a\n");scanf("%s",name);getchar();a=rmdir(name);if(a==-1){printf("目錄不存在\n");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{printf("目錄刪除成功");printf("\n");}}voidcreatefile(){inta;charname[10],choice;label:printf("請輸入文件路徑和名字");scanf("%s",name);getchar();//a=mkdir(name);a=creat(name,S_IWRITE);if(a==-1){printf("文件名相同\n");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{printf("文件創(chuàng)立成功");printf("\n");}}/*voidopenfile(){FILE*fp;charname[10];printf("請輸入要翻開的文件路徑和名字");scanf("%s",name);getchar();if((fp=fopen(name,"r"))==NULL){printf("文件不存在\n");return;}elseprintf("翻開文件成功\n");}*/voidreadfile(){charch,name[10];FILE*fp;printf("請輸入要讀的文件路徑和名字");scanf("%s",name);getchar();if((fp=fopen(name,"r"))==NULL){printf("文件不存在");return;}//openfile();ch=fgetc(fp);if(ch==EOF){printf("文本內容為空\n");}else{while(ch!=EOF){putchar(ch);ch=fgetc(fp);}printf("\n");fclose(fp);}}voiddeletefile(){FILE*fp;inta;charname[10],choice;label:printf("請輸入要刪除的文件路徑和名字");scanf("%s",name);getchar();fp=fopen(name,"r");a=access(name,0);//獲取文件狀態(tài)if(a!=0){printf("文件不存在");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{a=access(name,02);//#defineW_OK2if(a!=0){printf("文件為只讀文件");}else{fclose(fp);unlink(name);//刪除一個文件,假設成功那么返回0,否那么返回-1printf("刪除文件成功\n");}}}voidwritefile(){FILE*fp;charch,name[10],choice;label:printf("請輸入文件路徑和名字");scanf("%s",name);getchar();if((fp=fopen(name,"w"))==NULL){printf("文件不存在或只能讀");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;elsereturn;}//ch=getchar();printf("請輸入文件內容,#結束");ch=getchar();while(ch!='#'){fputc(ch,fp);//putchar(ch);ch=getchar();}printf("文件內容輸入成功\n");getchar();fclose(fp);}/*voidcopyfile()//復制文件操作{charname[20],name1[20],name2[20];printf("請輸入被復制的文件名");scanf("%s",name);getchar();printf("請輸入復制后的文件名");scanf("%s",name1);getchar();strcpy(name2,"copy");//windowsstrcat(name2,name);strcat(name2,"");strcat(name2,name1);system(name2);//系統(tǒng)調用dos指令getchar();}*/voidcopyfile(){FILE*fp=NULL;FILE*fp2=NULL;inta;charch,name[50],name2[50],choice;printf("請輸入要被復制的文件路徑和名字");scanf("%s",name);label:printf("請輸入新文件路徑和名字");scanf("%s",name2);getchar();a=creat(name2,0);chmod(name2,S_IWRITE);if(a==-1){printf("文件夾名相同\n");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}fp=fopen(name,"r");//puts(name);puts(name2);if(fp)printf("....dddd");fp2=fopen(name2,"w");//printf("ll");if(fp2==0)printf("....");ch=fgetc(fp);//printf("kkk");while(ch!=EOF){//putchar(ch);fputc(ch,fp2);ch=fgetc(fp);}printf("復制文件成功");fclose(fp);fclose(fp2);printf("\n");}voidmodifyfile()/*修改文件權限*/{inta,x;charname[10],choice;label:printf("請輸入要修改權限的文件名");scanf("%s",name);getchar();a=access(name,0);//獲取文件的狀態(tài)if(a!=0){printf("文件不存在\n");printf("重新輸入?(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{printf("請選擇:1--只讀2--可寫\n");while(1){scanf("%d",&x);if(x==1||x==2)break;elseprintf("輸入錯誤!請重新選擇");}if(x==1){a=chmod(name,S_IREAD);/*修改文件為"只讀"*/printf("已經使<%s>只讀\n",name);getchar();}elseif(x==2)/*修改文件為"只寫"*/{a=chmod(name,S_IWRITE);printf("已經使<%s>可寫\n",name);getchar();}}}voidopenfile(){inta;charname[10],name2[10],choice;label:printf("請輸入要顯示的目錄");scanf("%s",name);/*顯示目錄操作*/getchar();a=access(name,0);if(a!=0){printf("目錄不存在");printf("重新輸入(Y/N)");scanf("%c",&choice);getchar();if(choice=='Y'||choice=='y')gotolabel;}else{printf("文件翻開成功,文件信息如下:\n");strcpy(name2,"dir");/*復制dir命令*/strcat(name2,name);printf("%s",name2);system(name2);/*系統(tǒng)調用*/}}voidmain(){label:mean();inti;printf("請選擇:");scanf("%d",&i);switch(i){case1:system("cls");createcatalog();break;//創(chuàng)立文件目錄case2:system("cls");deletecatalog();break;//刪除文件目錄case3:system("cls");createfile();break;//創(chuàng)立文件case4:system("cls");modifyfile();break;//修改文件權限case5:system("cls");writefile();break;//寫文件case6:system("cls");readfile();break;//讀文件case7:system("cls");deletefile();break;//刪除文件case8:system("cls");copyfile();break;//復制文件case9:system("cls");openfile();break;case10:exit(0);//關閉文件//case12:system("cls");openf

溫馨提示

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

評論

0/150

提交評論