檔案管理系統 (轉)
/***********文 件 管 理 系 統***********/
#include
#include
#include
#include
#include
#include
#include
#include
int init() /*初始化操作介面函式*/
{int i;
clrscr();
gotoxy(23,4);printf("* * * * * * * * * * * * * *");
gotoxy(27,5);printf("FILE MANAGE SYSTEM");
gotoxy(23,6);printf("* * * * * * * * * * * * * *");
gotoxy(28,9);printf("1--Creat File");
gotoxy(28,10);printf("2--Delete File");
gotoxy(28,11);printf("3--OPen File");
gotoxy(28,12);printf("4--Write File");
gotoxy(28,13);printf("5--Locate File");
gotoxy(28,14);printf("6--Modify File");
gotoxy(28,15);printf("7--Copy File");
gotoxy(28,16);printf("8--Move File");
gotoxy(28,17);printf("9--Cataloge Manage");
gotoxy(28,18);printf("10--Exit File");
gotoxy(25,21);
printf("Please Choice:");
scanf("%d",&i);
return(i); /*選擇相應的序號,相應的操作*/
}
main()
{int x,i,j,flag=1;
char name[15],name1[15],name2[40];
char choice,ch;
int handle,status; /*定義檔案的指標和狀態*/
FILE *fp;
while(flag) /*初始化介面*/
{i=init();
getchar();
switch(i)
{ case 1:label1: /*建立檔案操作*/
clrscr();
gotoxy(27,5);printf("CREAT FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the creating file name and routine:n");
scanf("%s",name);
getchar();
handle=creatnew(name,0);/*按指定的檔案方式建立檔案,若有同名檔案返回錯誤程式碼*/
if(handle==-1)
{ printf("nSorry,the file already exists.");
getchar();
printf("nInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label1;
}
else { printf("nThe file is created.");
printf("Do you now input contentof the file?(Y or N):");
while(1) /*輸入建立檔案的內容*/
{ scanf("%c",&choice);
if(choice=='y'||choice=='n'||choice=='Y'||choice=='N')
break;
else
printf("nError!Please input again!");
}
if(choice=='y'||choice=='Y')
{ printf("nNow input content to the file(End with '#'):nn");
fp=fopen(name,'w');/*把內容存放到fp指向的檔案中去*/
ch=getchar();
while(ch!='#')
{ fputc(ch,fp);
ch=getchar();
}
fclose(fp);getchar();/*關閉檔案*/
}
getchar();
break;
case 2:label2: /*刪除檔案的操作*/
clrscr();
gotoxy(25,5);printf("DELETE FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the deleting file name and routine:n");
scanf("%s",name); /*輸入要刪除的檔名*/
getchar();
printf("n Are you sure?(Y or N):");
while(1)
{ scanf("%c",&choice);
if(choice=='y'||choice=='n'||choice=='Y'||choice=='N')
break;
else
printf("nError!Please input again!");
}
if(choice=='y'||choice=='Y')
{status=access(name,0);/*獲取檔案的狀態,是否存在*/
if(status!=0)
{printf("nSorry the file doesn't exist!");
getchar();
printf("nnInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label2;
}
else
{ status=access(name,02);/*獲取檔案的狀態,是否存在並且是否只讀*/
if(status!=0)
{ printf("nSorry the file is only read!");
getchar();
}
else
{unlink(name); /*從目錄中刪除一個檔案函式,該函式在dos.h中*/
printf("nndelete succefully!");
getchar();
}
}
}
getchar();
break;
case 3:label3: /*開啟檔案操作*/
clrscr();
gotoxy(27,5);printf("OPEN FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the opening file name and routine:n");
scanf("%s",name);
status=access(name,0);/*獲取檔案的狀態*/
if(status!=0)
{printf("nSorry the file doesn't exist!");
getchar();
printf("nnInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label3;
}
else
{ printf("nNow begin to read the file:n");
fp=fopen(name,'r');
ch=fgetc(fp); /*讀出檔案到*/
while(ch!=EOF)
{printf("%c",ch);
ch=fgetc(fp);j++;
}
fclose(fp);getchar();/*關閉檔案*/
}
getchar();
break;
case 4:label4: /*寫檔案操作*/
clrscr();
gotoxy(27,5);printf("WRITE FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the writing file name and routine:n");
scanf("%s",name);
status=access(name,0);/*獲取name指向的檔案狀態*/
if(status!=0)
{printf("nSorry the file doesn't exist!");
getchar();
printf("nnInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label4;
}
else
{fp=fopen(name,'w');/*以寫入方式開啟name 指向的檔案*/
printf("nPlease input the information(end with '#'):n");
ch=getchar(); /*重寫檔案*/
while(ch!='#')
{ fputc(ch,fp);
ch=getchar();
}
fclose(fp);getchar();/*關閉檔案*/
}
getchar();
break;
case 5:label5: /*定位檔案操作*/
clrscr();
gotoxy(27,5);printf("LOCATE FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the locating file name and routine:n");
scanf("%s",name);
status=access(name,0);/*獲取name檔案指向的檔案的狀態*/
if(status!=0)
{printf("nSorry the file doesn't exist!");
getchar();
printf("nnInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label5;
}
else
{printf("nPlease input the location:");
scanf("%d",&x);
handle=open(name,O_CREAT|O_RDWR,S_IREAD|S_IWRITE);/*開啟由name指定的檔案,name既可以是簡單的檔名*/
/*也可以是檔案的路徑名,O_CREAT表示了開啟檔案的存取程式碼,若檔案不存在,則建立,否則無效。*/
/*O_RDWR表示開啟檔案用於讀寫。S_IREAD|S_IWRITE允許讀寫*/
lseek(handle,x,SEEK_SET);/*該函式把由handle指定的檔案的檔案指標,移到SEEK_SET(開始位置)再加上x偏移量的地方*/
getchar();
}
getchar();
break;
case 6:label6: /*修改檔案屬性操作*/
clrscr();
gotoxy(27,5);printf("MODIFY FILEn");
for(j=0;j<80;j++)
printf("= ");
printf("nnPlease input the modifying attribution file name and routine:n");
scanf("%s",name);
status=access(name,0);/*獲取檔案的狀態*/
if(status!=0)
{printf("nSorry the file doesn't exist!");
getchar();
printf("nnInput again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label6;
}
else
{ printf("nPlease choice:1--READ_ONLY 2--WRITE_ONLY");
printf("nnPlease choice the attributione operation:");
while(1)
{ scanf("%d",&x);
if(x==1||x==2)
break;
else
printf("nError!Please input again!");
}
if(x==1) { status=chmod(name,S_IREAD);/*修改檔案為“只讀”*/
if(status)
printf("nSorry!Couldn't make the file read_only!");
else
printf("n===Made read_only===",name);
getchar();
}
else if(x==2) /*修改檔案為“只寫”*/
{ status=chmod(name,S_IWRITE);
if(status)
printf("nSorry!Couldn't make the file write_only!");
else
printf("n===Made write_only===",name);
getchar();
}
}
getchar();
break;
case 7:clrscr(); /*複製檔案的操作*/
gotoxy(27,5);printf("COPY FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the copying file name and routine:n");
scanf("%s",name);
getchar();
printf("nPlease input the copyed file name and routine:n");
scanf("%s",name1);
getchar();
strcpy(name2,"copy ");
strcat(name2,name);
strcat(name2," ");
strcat(name2,name1);
system(name2); /*系統dos指令*/
getchar();
break;
case 8:clrscr(); /*移動檔案操作*/
gotoxy(27,5);printf("MOVE FILEn");
for(j=0;j<40;j++)
printf("= ");
printf("nnPlease input the moving file name and routine:n");
scanf("%s",name);
getchar();
printf("nPlease input the moving file name and routine:n");
scanf("%s",name1);
getchar();
strcpy(name2,"move ");
strcat(name2,name);
strcat(name2," ");
strcat(name2,name1);
system(name2); /*系統呼叫dos指令*/
getchar();
break;
case 9: label9: /*目錄管理操作*/
clrscr();
gotoxy(27,5);printf("CATALOGUE MANAGEn");
for(j=0;j<40;j++)
printf("= ");
gotoxy(13,9);
printf("Please input the moving file name and routine:n");
gotoxy(25,11);printf("1--display catalogue");
gotoxy(25,12);printf("2--creat catalogue");
gotoxy(25,13);printf("3--detele catalogue");
gotoxy(25,14);printf("4--copy catalogue");
gotoxy(25,15);printf("5--move catalogue");
gotoxy(25,16);printf("6--exit catalogue");
gotoxy(26,20);
printf("Please choice:");
scanf("%d",&x);
while(x<1||x>6)
{printf("nError!Please input again!n");
scanf("%d",&x);
}
switch(x)
{ case 1: printf("nPlease iuput the displaying catalogue:n");
scanf("%s",name);/*縣是目錄操作*/
strcpy(name2,"dir ");/*複製dir命令*/
strcat(name2, name);
printf("%s",name2);
getchar();
system(name2);/*系統呼叫*/
getchar();
break;
case 2: printf("nPlease iuput the creating catalogue:n");
scanf("%s",name);/*建立目錄操作*/
strcpy(name2,"md ");/*複製md命令*/
strcat(name2,name);
system(name2);/*系統呼叫*/
getchar();
break;
case 3: printf("nPlease iuput the deleting catalogue:n");
scanf("%s",name);/*刪除目錄操作*/
strcpy(name2,"rd ");/*複製rd命令*/
strcat(name2,name);
system(name2);
getchar();
break;
case 4: printf("nPlease iuput the copying catalogue:n");
scanf("%s",name);/*複製目錄操作*/
printf("nPlease iuput the displayed catalogue:n");
scanf("%s",name1);
strcpy(name2,"xcopy ");/*複製xcopy命令*/
strcat(name2,name);
strcat(name2," ");
strcat(name2,name1);
strcat(name2,"/e");
system(name2);/*系統呼叫*/
getchar();break;
case 5: printf("nPlease iuput the moving catalogue:n");
scanf("%s",name);/*移動目錄操作*/
printf("nPlease iuput the moved catalogue:n");
scanf("%s",name1);
strcpy(name2,"move ");/*複製move命令*/
strcat(name2,name);
strcat(name2," ");
strcat(name2,name1);
system(name2);
getchar();break;
case 6:goto tag; /*退出目錄管理操作*/
}
printf("Input again?(Y or N)");
scanf("%c",&choice);getchar();
if(choice=='Y'||choice=='y')
goto label9;
tag:getchar();
break;
case 10:flag=0;exit(0);break; /*退出系統*/
default: clrscr();
printf("nn Error!Please input again!n");
getchar();
break;
}
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-993857/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Solaris 檔案系統管理(轉)
- R檔案系統管理
- 【Solaris】Solaris檔案系統管理1 UFS檔案系統的建立
- 【Solaris】Solaris檔案系統管理3 ZFS檔案系統的建立
- 磁碟管理與檔案系統
- 轉-AIX檔案系統滿AI
- 理解 Proc 檔案系統(轉)
- Linux檔案系統 (轉)Linux
- 標籤化檔案管理系統
- 檔案系統操作與磁碟管理
- 檔案管理系統助力檔案資訊化建設
- Linux檔案系統-目錄和檔案管理Linux
- Linux 檔案系統-ext3 檔案系統介紹(轉)Linux
- 細說GNU/Linux系統的檔案及檔案系統(轉)Linux
- Linux作業系統檔案管理器的共享(轉)Linux作業系統
- Linux教程-系統管理-/etc下的檔案詳解(轉)Linux
- 系統管理員秘訣:檢查誰刪除了檔案(轉)
- 使用 /proc 檔案系統來控制系統(轉)
- 轉:SAP專案管理系統速成專案管理
- 檔案系統&&磁碟管理(六)–swap分割槽、迴環裝置、檔案系統配置檔案fstab
- CRM系統中的文件檔案管理
- Path Finder 10 for mac系統檔案管理Mac
- 使用 Fstransform 轉換檔案系統ORM
- 快速載入系統檔案(轉)
- FreeBSD建立檔案系統(轉)
- 裝置檔案系統教程(轉)
- FAT32 檔案系統 (轉)
- Windows系統檔案詳解(轉)Windows
- 網路管理員指南 -11.網路檔案系統NFS -3>輸出檔案(轉)NFS
- Linux下NFS網路檔案系統設定及管理(轉)LinuxNFS
- 【Solaris】Solaris檔案系統管理6 磁碟配額管理
- 工程專案管理系統的理解(轉)專案管理
- 專案管理資訊系統(PMIS)(轉)專案管理
- 『學了就忘』Linux檔案系統管理 — 57、Linux檔案系統介紹Linux
- 【Solaris】Solaris檔案系統管理4 ZFS檔案系統備份、刪除與恢復
- 作業系統實驗5 簡易檔案管理系統作業系統
- Linux系統學習之檔案管理Linux
- 電腦檔案系統的管理總結