当前位置:首页 > 计算机操作系统实验讲义
void create(char *str,int num)//在当前目录下创建一个名字为str的文件,长度为num
{
int flag=1;//1表示没有与该名字重名的文件 DirectoryNode *tempnode,*newnode; tempnode=workDirFile->subFile;
while(tempnode)//查找该结点,若有重名文件则报错 { if(tempnode->type==1) { if(!stricmp(tempnode->name,str)) { printf(\ flag=0; } } if (flag==0) break; tempnode=tempnode->next; }
tempnode=workDirFile->subFile; if(flag) { newnode=new DirectoryNode; strcpy(newnode->name,str); newnode->size=num; newnode->type=1; newnode->next=NULL; if(tempnode!=NULL) { while(tempnode->next) { tempnode=tempnode->next; } tempnode->next=newnode; } else { workDirFile->subFile=newnode; } } }
//显示从根目录开始的所有目录和文件及其层次结点
void lsall()//要使用在头文件中定义的队列结构 {
struct DirectoryNode *temp; struct DirectoryNode *tempnode; DataType data; Tp sq;
temp=workDirFile; InitCycQueue(&sq); data.DirFile=&root; strcpy(data.name,\ EncycQueue(&sq,data);
while(Empty(&sq)) { data=OutCycQueue(&sq); printf(\ workDirFile=data.DirFile; dir(); tempnode=workDirFile->subFile; while(tempnode) { if(tempnode->type==0) { data.DirFile=tempnode; strcpy(data.name,tempnode->name); EncycQueue(&sq,data); } tempnode=tempnode->next; } }
workDirFile=temp; }
void cd(char *str)//str表示当前目录下的某个子目录名,如果存在则转移到该目录下
{
int flag=1;
DirectoryNode *tempnode;
tempnode=workDirFile->subFile; if(!stricmp(str,\改变到根目录下 { strcpy(path,\ workDirFile=&root;
flag=0; } else { while(tempnode && flag)//改变到某个目录下 { if(tempnode->type==0) { if(!stricmp(tempnode->name,str)) { workDirFile=tempnode; strcat(path,\ strcat(path,str); flag=0; } } tempnode=tempnode->next; } } if(flag) cout< void del(char *str)//删除文件 { int flag=1; char ch='y'; DirectoryNode *tempnode,*oldtempnode; tempnode=workDirFile->subFile; oldtempnode=tempnode; while(tempnode && flag) { if(tempnode->type==1) { if(!stricmp(tempnode->name,str)) { cout< free(tempnode); } else flag=0; } //删除成功! } oldtempnode=tempnode; tempnode=tempnode->next; } if(flag) cout< void delnode(DirectoryNode *curnode)//删除当前目录下的名字curnode的结点 { struct DirectoryNode *tempnode,*tempArraynode; if(curnode==NULL) return; if(curnode->type==0) { tempnode=curnode->subFile; while(tempnode) { tempArraynode=tempnode; tempnode=tempnode->next; delnode(tempArraynode);//递归调用 } } delete curnode; } void rd(char *str)//删除当前目录下的名字为str的子目录 { int flag=0; char ch='y'; DirectoryNode *tempnode,*oldtempnode; oldtempnode=NULL; tempnode=workDirFile->subFile; while(tempnode&&!flag) { if(tempnode->type==0) { if(!stricmp(tempnode->name,str)) flag=1; }
共分享92篇相关文档