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

📄 8-9.c

📁 《C程序员成长攻略》-黎陡-源代码-4282 中国水利水电出版社 程序员成长之路丛书
💻 C
字号:
#include"stdio.h"
#include"dos.h"

int FindFile(char far *file)
{
	union REGS inregs,outregs;
	struct SREGS sregs;
	inregs.h.ah=0x4e;
	inregs.x.dx=FP_OFF(file);
	sregs.ds=FP_SEG(file);
	intdosx(&inregs,&outregs,&sregs);
	if(outregs.x.cflag==0)
	{
		printf("File %s is exist.\n",file);
		return 1;
	}
	else
	{
		printf("File %s is not exist.\n",file);
		printf("Press any key to return.\n");
		return 0;
	}
}

int GetAttribute(char far *file)
{
	union REGS inregs,outregs;
	struct SREGS sregs;
	inregs.h.ah=0x43;
	inregs.h.al=0x00;
	inregs.x.dx=FP_OFF(file);
	sregs.ds=FP_SEG(file);
	intdosx(&inregs,&outregs,&sregs);
	if(outregs.x.cflag==0)
	{
		printf("%s attribute is : %x\n",file,outregs.x.cl);
		return outregs.x.cx;
	}
	else
	{
		printf("Unable to get the file attribute.\n");
		return 0;
	}
}

int DeleteFile(char far *file)
{
	char ch;
	union REGS inregs,outregs;
	struct SREGS sregs;
	inregs.h.ah=0x41;
	inregs.x.dx=FP_OFF(file);
	sregs.ds=FP_SEG(file);
	printf("Are you sure you want to delete File %s?(Y/N)\n",file);
	while(1)
	{
		scanf("%c",&ch);
		if(ch=='y' || ch=='Y')
		{
			intdosx(&inregs,&outregs,&sregs);
			if(outregs.x.cflag==0)
			{
				printf("Delete File %s Success!\n",file);
				printf("Press any key to return.\n");
				return 1;
			}
			else
			{
				printf("Failed to Delete File %s!\n",file);
				printf("Press any key to return.\n");
				return 0;
			}
		}
		else
		if(ch=='n' || ch=='N')
		{
			printf("Press any key to return.\n");
			return 0;
		}
	}
}

int ChangeFile(char far *oldfile,char far *newfile)
{
	union REGS inregs,outregs;
	struct SREGS sregs;
	inregs.h.ah=0x56;
	inregs.x.dx=FP_OFF(oldfile);
	sregs.ds=FP_SEG(oldfile);
	sregs.es=FP_OFF(newfile);
	inregs.x.di=FP_SEG(newfile);
	intdosx(&inregs,&outregs,&sregs);
	if(outregs.x.cflag==0)
	{
		printf("Change File %s Success!\n",oldfile);
		printf("New File is %s.\n",newfile);
		return 1;
	}
	else
	{
		printf("Failed to Change File %s!\n",oldfile);
		printf("Press any key to return.\n");
		return 0;
	}
}
main()
{
	char file[100],newfile[100];
	int FindFlag;
	char ch;
	clrscr();
	printf("*****************************************************\n");
	printf("Please enter the file name you want to find:\n");
	gets(file);
	FindFlag=FindFile(file);
	if(FindFlag)
	{
		printf("--------------------------------------\n");
		GetAttribute(file);
		printf("--------------------------------------\n");
		printf("Select Operations:\n");
		printf("1. Delete\n");
		printf("2. Change\n");
		printf("--------------------------------------\n");
		while(1)
		{
			scanf("%c",&ch);
			if(ch=='1')
			{
				DeleteFile(file);
				break;
			}
			else
			if(ch=='2')
			{
				printf("Please input new file-name:\n");
				gets(newfile);
				ChangeFile(file,newfile);
				break;
			}
			else
				printf("Input Error!\n");
		}
	}
	getch();
}

⌨️ 快捷键说明

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