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

📄 filesystem.cpp

📁 简单文件管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}//结束print_currentpath

////////////函数描述:打印版本信息
VRESULT FileSystem::cdmodule()//cd模块函数,改变当前目录                        cd
{
	switch(pathflag)
	{
	case 0:
	case 1:  find();
		     if((*temp2).isdir==1)
				 path_currentpath();
			 else
				 error(105);//使用cd命令不能进入文件中
			 break;
	case 5:  break;//没有输入路径
	case -1:  break;
	case -2: error(100);break;
	}
	print_currentpath();
}//结束cd模块函数

///////////////函数描述:打印版本信息
VRESULT FileSystem::editmodule()//edit模块函数,创建文件                      edit
{
	switch(pathflag)
	{
	case 0:
	case 1:  error(101);break;//目录或者文件已存在
	case 5:  error(102);break;//目录名或者文件名不能为空
	case -1: error(100);break;//无效的或者错误的路径
	case -2: set_into_table(0);
		     printf("    一个文件已经被创建!\n");break;//将新节点插入到目录树
	}
	print_currentpath();

}//结束edit模块函数

//////////////函数描述:打印版本信息  
VRESULT FileSystem::delmodule()//del模块函数,删除节点                        del
{ 
	switch(pathflag)
	{
	case -2:
	case -1: error(100);break;
	case 5:  error(102);break;
	case 0:
	case 1:  del_from_table();break;//将指定的节点从目录树中删除
	}
	print_currentpath();
}//结束del模块函数

/////////////函数描述:打印版本信息
VRESULT FileSystem::dirmodule()//dir模块函数,显示目录                       dir
{
	switch(pathflag)
	{
	case -2:
	case -1: error(100);break;
	case 5:  
	case 0:
	case 1:  print_table();break; //打印指定的目录下的文件或目录
	}
	print_currentpath();
}//结束dir模块函数

///////////函数描述:打印版本信息
VRESULT FileSystem::mdmodule()//md模块函数,创建目录                         md
{
	switch(pathflag)
	{
	case 0:
	case 1:  error(101);break;
	case 5:  error(102);break;//目录名或者文件名不能为空
	case -1: error(100);break;
	case -2: set_into_table(1);
		     printf("    一个目录已经被创建!\n");break;//将新节点插入到目录树
	}
	print_currentpath();
}//结束md模块函数

////////////函数描述:打印版本信息
VRESULT FileSystem::rdmodule()//rd模块函数,删除目录                          rd
{
	switch(pathflag)
	{
	case -2:
	case -1: error(100);break;
	case 5:  error(102);break;
	case 0:
	case 1:  areyousure();break;       //确定删除目录及内容
	}
	print_currentpath();
}//结束md模块函数

//////////函数描述:打印版本信息
VRESULT FileSystem::currentpath_path()//把当前目录存入PArootH中
{
	int q;
	for(i=0;i<10;i++)
	{
		if(!strcmp(currentpath[i],"\0"))
		{
			q=i;
			break;
		}
		else
			strcpy(path[i],currentpath[i]);
	}    //如果currentpath的长度比path现有长度还要短,则要把长出的部分清空
	for(j=q;j<10;j++)
	{
		for(i=0;i<8;i++)
		{
			path[j][i]='\0';
		}
	}
}//结束路径的复制

//////////函数描述:打印版本信息
VRESULT FileSystem::path_currentpath()//path复制到当前路径中
{
	int u;
	for(i=1;i<10;i++)//从i=1开始是为了在输入的路径为空的时候保留根节点
	{
		if(!strcmp(path[i],"\0"))
		{
			u=i;
			break;
		}
		else
			strcpy(currentpath[i],path[i]);
	}	//如果path的长度比currentpath现有长度还要短,则要把长出的部分清空
	for(j=u;j<10;j++)
	{
		for(i=0;i<8;i++)
		{
			currentpath[j][i]='\0';
		}
	}
}//结束路径的复制

/////////函数描述:打印版本信息
VRESULT FileSystem::inputpath_path()//把输入的路径存入path中
{
	int o;
	for(i=0;i<10;i++)
	{
		if(!strcmp(inputpath[i],"\0"))
		{
			o=i;
			break;
		}
		else
			strcpy(path[i],inputpath[i]);
	}	//如果inputpath的长度比path现有长度还要短,则要把长出的部分清空
	for(j=o;j<10;j++)
	{
		for(i=0;i<8;i++)
		{
			path[j][i]='\0';
		}
	}
}//结束路径的复制

//////////函数描述:打印版本信息
VRESULT FileSystem::current_input_path()//把当前路径和输入的路径连接起来存入path中
{   int n,t;
	for(i=0;i<10;i++)
	{
		if(!strcmp(currentpath[i],"\0"))
		{
			t=i;//这里的有关长度的控制就不说什么了,小心点就好啦
			break;//又犯了个错误,次序弄错了,没存就跳出了
		}
		else
			strcpy(path[i],currentpath[i]);
	}
	for(i=t;i<10;i++)
	{
		if(!strcmp(inputpath[i-t],"\0"))
		{
			n=i+1;
			break;
		}
		else
			strcpy(path[i],inputpath[i-t]);
	}    //如果新输入路径的长度比path现有长度还要短,则要把长出的部分清空
    for(j=n;j<10;j++)
	{
		for(i=0;i<8;i++)
		{
			path[j][i]='\0';
		}
	}
}//结束路径的复制

//////////函数描述:打印版本信息
VRESULT FileSystem::current_input_1_path()//把当前路径和输入的路径(除掉最后一个)连接起来存入path中
{
	int v,s;
	for(i=0;i<10;i++)//先把currentpath放入path中,并记录了path的现有长度s
		                //这里的问题是经常不知道要不要减1
	{
		if(!strcmp(currentpath[i],"\0"))
		{
			break;
			s=i-1;
		}
		else
			strcpy(path[i],currentpath[i]);
	}
	for(i=0;i<10;i++)//查inputpath的长度,得到长度v
	{
		if(!strcmp(inputpath[i],"\0"))
		{
			break;
			v=i-1;
		}
	}
	for(i=j+1;i<(s+v);i++)/*path已有长度j,inputpath的长度v,inputpath还要去掉一个,
		                    所以从j+1开始到j+v-1*/
	{
		strcpy(path[i],inputpath[i-s]);
	}
}//结束路径的复制

//////////函数描述:打印版本信息
VRESULT FileSystem::find()//查找路径在二叉树中的位置
{
	/*temp指向了路径最后一个节点的下一个子节点
	  temp2指向了路径最后一个节点
	  temp3指向的节点的兄弟节点为路径最后一个节点,即为路径最后一个节点的上一个兄弟节点
	  temp4指向最后一个节点的父节点*/
	temp=root;
	temp2=root;
	temp3=root;
	temp4=root;
	for(i=0;i<10;i++)
	{
		if(!strcmp(path[i],"\0"))
			break;
		while(temp!=NULL)
		{
			if(!strcmp(path[i],(*temp).filename))
				break;
			else 
			{
				temp3=temp;
				temp=(*temp).sibling;
			}
		}
		temp4=temp2;
		temp2=temp;
		temp=(*temp).child;
		
	}
}//结束查找路径在二叉树中的位置

///////////函数描述:打印版本信息
VRESULT FileSystem::set_into_table(int r)//将新节点插入到目录树
{
	find();//查找路径在二叉树中的位置
	getnewnode();//申请新的节点空间
	strcpy((*newnode).filename,newname);
	(*newnode).isdir=r;
	(*newnode).child=NULL;//此时newnode指向newname
	/*如果此时temp2的子节点为空,直接把temp2子节点指向新节点,不为空则
	  先查找temp2子节点的最右边的兄弟节点,再把这个节点的兄弟节点指向新节点,操作如下*/
	if((*temp2).child!=NULL)
	{
		temp2=(*temp2).child;
		while(temp2!=NULL)
		{
			temp3=temp2;
			temp2=(*temp2).sibling;
		}
		(*newnode).sibling=NULL;
		(*temp3).sibling=newnode;
	}
	else 
	{
		(*newnode).sibling=NULL;
		(*temp2).child=newnode;
	}
}//结束将新节点插入到目录树函数

///////////函数描述:打印版本信息
VRESULT FileSystem::del_from_table()//将指定的节点从目录树中删除
{
	find();//查找路径在二叉树中的位置
	if((*temp2).isdir==1)
		error(107);//错误:不能用del命令删除目录,请指定一个文件名
	else
	{
		if(temp3!=NULL)
			(*temp3).sibling=(*temp2).sibling;
		else
			(*temp4).child=(*temp2).sibling;
		printf("    一个文件已经被删除!\n");
	}
}//结束将指定的节点从目录树中删除函数

///////////函数描述:打印版本信息
VRESULT FileSystem::print_table()//打印指定的目录下的文件或目录
{
	int count1=0;
	int count2=0;
	find();//查找路径在二叉树中的位置
	while(temp!=NULL)
	{
		printf("%s",(*temp).filename);
		if((*temp).isdir==1)
		{
			count1++;
			printf("          <dir>\n");
		}
		else
		{
			count2++;
			printf("          <file>\n");
		}
		temp=(*temp).sibling;
	}
	printf("    共有");
	printf("%d个目录",count1);
	printf("    共有");
	printf("%d个文件\n",count2);
}//结束打印指定的目录下的文件或目录函数

////////////函数描述:打印版本信息
VRESULT FileSystem::areyousure()//确定删除目录及内容
{
	char p;
	for(i=0;i<10;i++)
	{
		if(!strcmp(currentpath[i],"\0"))
			break;
	}
	for(j=0;j<10;j++)//类似二维数组
	{
		if(!strcmp(path[j],"\0"))
			break;
	}
	if(i>=j)
		error(108);//错误:不能删除上级目录或同级目录
	else
	{
	find();//查找路径在二叉树中的位置
	if((*temp2).isdir==0)
		error(106);//错误:不能用rd命令删除文件,请指定一个目录名
	else
	{
		printf("    确定删除该目录以及目录下所有文件和目录?[y/n]");
		p=getchar();
		if(p=='n')
			printf("    没有进行删除操作\n");
		else if(p=='y')
		{
			if(temp3==root)
				(*temp3).child=(*temp2).sibling;
			else
			{
				if(temp3!=NULL)
					(*temp3).sibling=(*temp2).sibling;
				else
					(*temp4).child=(*temp2).sibling;
			}
			printf("    一个目录已经被删除!\n");
			p='a';//把P换成Y、N之外的任意一个字符
		}
		else 
			error(103);
	}
	}
}//结束确定删除目录及内容函数

///////////函数描述:打印版本信息
VRESULT FileSystem::reclaim()//把指针temp,temp2复位,inputpath,newname,orderline,order,path清空
{
	temp=root;
	temp2=root;
	temp3=root;
	temp4=root;
	for(i=0;i<10;i++)
	{
		for(j=0;j<8;j++)
		{
			inputpath[i][j]='\0';
			path[i][j]='\0';
		}
	}
	for(i=0;i<50;i++)
	{
		orderline[i]='\0';
	}
	for(i=0;i<5;i++)
	{
		order[i]='\0';
	}
	for(i=0;i<8;i++)
	{
		newname[i]='\0';
	}

}//结束复位函数

///////////函数描述:打印版本信息
VRESULT FileSystem::exit_command()
{
}

void main()
{
	printf("                       操作系统课程设计--简单文件管理系统      \n") ;
	printf("                姓名:周玉祥    班级:计062    学号:200600401079\n");
	FileSystem *pFileSystem = new FileSystem() ;
	pFileSystem->run() ;

}

⌨️ 快捷键说明

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