王朝网络
分享
 
 
 

文件管理系统

王朝other·作者佚名  2006-01-08
宽屏版  字体: |||超大  

/***********文 件 管 理 系 统***********/

#include <stdio.h>

#include <stdlib.h> /*不容易归类的标准函数库*/

#include <conio.h>

#include <string.h>

#include <sys\stat.h>

#include <fcntl.h> /*非标准文件输入输出操作的代码符号属性*/

#include <dos.h>

#include <io.h>

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 FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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 '#'):\n\n");

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 FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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("\n\nInput 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("\n\ndelete succefully!");

getchar();

}

}

}

getchar();

break;

case 3:label3: /*打开文件操作*/

clrscr();

gotoxy(27,5);printf("OPEN FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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("\n\nInput 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 FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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("\n\nInput 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 FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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("\n\nInput 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 FILE\n");

for(j=0;j<80;j++)

printf("= ");

printf("\n\nPlease 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("\n\nInput 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("\n\nPlease 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 <%s> 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 <%s> write_only===",name);

getchar();

}

}

getchar();

break;

case 7:clrscr(); /*复制文件的操作*/

gotoxy(27,5);printf("COPY FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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 FILE\n");

for(j=0;j<40;j++)

printf("= ");

printf("\n\nPlease 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 MANAGE\n");

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("\n\n Error!Please input again!\n");

getchar();

break;

}

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有