计算机操作系统实验讲义

2026/4/24 21:46:09

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<>ch; if(ch='y'||ch=='Y') { if(tempnode==workDirFile->subFile) workDirFile->subFile=tempnode->next; else oldtempnode->next=tempnode->next; flag=0;

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; }


计算机操作系统实验讲义.doc 将本文的Word文档下载到电脑
搜索更多关于: 计算机操作系统实验讲义 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219