⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 新建 文本文档.txt

📁 本设计的目的是通过设计和调试一个简单的文件系统
💻 TXT
字号:
文件管理系统原代码
/***********文 件 管 理 系 统***********/
#include 
#include /*不容易归类的标准函数库*/
#include 
#include 
#include /*非标准文件输入输出操作的代码符号属性*/
#include 
#include 

int init() /*初始化操作界面函数*/
{
int i;

printf("* * * * * * * * * * * * * *\n");
printf("FILE MANAGE SYSTEM\n");
printf("* * * * * * * * * * * * * *\n");
printf("1--Creat File\n");
printf("2--Delete File\n");
printf("3--OPen File\n");
printf("4--Write File\n");
printf("5--Copy File\n");
printf("6--Modify File\n");
printf("7--Cataloge File\n");
printf("8--Exit File\n");

printf("Please Choice:");
scanf("%d",&i);
return(i); /*选择相应的序号,执行相应的操作*/
}
void check() //密码认证
{
char user[20];
int check;
char pin1[]="admin"; //此处设定用户口令
char pin[20];
aga:
printf("\n * ===================================================================== *");
printf("\n * *");
printf("\n * 文件管理系统--用户登录 *");
printf("\n * *");
printf("\n * ===================================================================== *");
printf("\n \1 请输入用户名:");
scanf ("%s",user);
printf(" \2 请输入密码:");
scanf ("%s",pin);
check=strcmp(pin,pin1);
if (check!=0)
{
system("cls");

printf("\n * Sorry, 密码有误,请重新输入! *");
goto aga;
}
else system("cls");
}
void createfile(); /*函数声明*/
void deletefile();
void openfile();
void writefile();
void copyfile();
void modifyfile();
void catalogue();

void main()

{

check();
/*int x,i,j,flag=1;
char name[15],name1[15],name2[40];
char choice,ch;
int handle,status; */ /*定义文件的指针和状态*/
int flag=1,i;
while(flag) /*初始化系统界面*/
{
i=init();
getchar();
switch(i)
{
case 1:createfile(); /*创建文件*/
break;
case 2:deletefile(); /*删除文件*/
break;
case 3:openfile(); /*打开文件*/
break;
case 4:writefile(); /*写文件*/
break;
case 5:copyfile(); /*拷贝文件*/
break;
case 6:modifyfile(); /*修改文件属性*/
break;
case 7:catalogue(); /*文件目录管理*/
break;
case 8:flag=0;exit(0);break; /*退出文件管理系统程序*/
default: 
printf("\n\n Error!Please input again!\n");
getchar();
break;
}
}
}

void createfile() /*创建文件操作*/
{
int j,handle;
char name[20],choice;
label1: 
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=creat(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.\n");
}
getchar();
}

void deletefile() /*删除文件的操作*/
{
int j,status;
char name[20],choice;
label2: 
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):");
scanf("%c",&choice);
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();
system("cls");
}
else
{
unlink(name); /*从目录中删除一个文件函数,该函数在dos.h中*/ 
printf("\n\ndelete succefully!");
getchar();
}
}
}
getchar();
}

void openfile() /*open the file*/
{
char ch,name[20];
FILE *fp;
printf("please input the name of the file: ");
scanf("%s",name);
if((fp=fopen(name,"r"))==NULL)
printf("cannot open!");
ch=fgetc(fp);
while (ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
getchar();
getchar();
printf("\n");
fclose(fp); /*close the file*/
system("cls");
}

void writefile() /*write the file*/
{
FILE *fp;
char ch,name[10];
label:printf("put the file's name:\n");
scanf("%s",name);
if((fp=fopen(name,"w"))==NULL)
{printf("cannot open file\n");goto label;}
ch=getchar();
printf("please input the file's content end with '#': \n");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);putchar(ch);
ch=getchar();
}
printf("\nThe file have been written!\n");
getchar();
getchar();
fclose(fp);
}

void copyfile() /* 复制文件操作*/
{
int j;
char name[20],name1[20],name2[20];
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();
}
void modifyfile() /*修改文件属性操作*/
{
int j,status,choice,x;
char name[20];
label6: 
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();
}
void catalogue() /*目录管理子程序*/
{
int j,x;
char name[20],name1[20],name2[20],choice;

label9: /*目录管理操作*/ 

printf("CATALOGUE MANAGE\n");
for(j=0;j<40;j++)
printf("= ");
printf("Please input the moving file name and routine:\n");
printf("1--display catalogue\n");
printf("2--creat catalogue\n");
printf("3--detele catalogue\n");
printf("4--copy catalogue\n");
printf("5--move catalogue\n");
printf("6--exit catalogue\n");

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();
printf("create catalogue successful!");
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();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -