您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页操作系统实验(七)文件管理

操作系统实验(七)文件管理

来源:意榕旅游网


实验七 文件管理(磁盘中创建和删除文件夹)

姓名:蒙吉 学号:20072411603 指导老师:曹玉林 实验目的:1)了解磁盘的物理组织。

2)掌握windows系统提供的有关对磁盘操作的函数。 3)根据输入的扇区号读/写指定扇区。 实验准备知识:需要了解已经学过的VC++工程文件的运行步骤以及它的操作界面常用的设置方法。

实验内容:在已做过的实验五、六的基础上编写一个程序,分别完成如下功能。

1) 有个help帮助提示。 2) 查看位示图。

3) 在目录文件中创建子目录。 4) 根据当前目录切换到指定目录。

5) 搜索所要删除的目录是否为空目录,若是则删除。 6) 在当前目录中创建文件名称。

7) 搜索所要删除的文件是否存在,若是则删除。 8) 列出当前目录的所有目录项,退出程序等。

实验要求:

深入理解操作系统设备当作文件处理的特性。 参考源代码:

// wjgl.cpp: implementation of the wjgl class. juzhen[0][j]=1; // } /////////////////////////////////////////////////////////////////// for(j=1;jname,\"C\"); { ml->awenjian=NULL; hang=16; ml->top=NULL; lie=16; ml->next=NULL; int j,k; ml->amulu=NULL;

} //cout<<\"矩阵的行\"<//cin>>hang;

wjgl::~wjgl() //cout<<\"矩阵的列\"<//cin>>lie; { srand(time(NULL)); for(j=0;j- 1 -

{ node1 *s; node1 *r; r=(node1 *)malloc(sizeof(node1)); return 0;

}

int wjgl::mk() s=(node1 *)malloc(sizeof(node1)); { s=ml; r=zhizhen; char mlname[20]; cin>>mlname; if(!strcmp(mlname,\"..\")) { if(zhizhen->top==NULL) { cout<<\"不存在该目录的根目 录\"<top; } // showweizhi(); return 0; } else { r=r->amulu; while(r!=NULL) { if(!strcmp(r->name,mlname)) { zhizhen=r; //showweizhi(); return 0; } else { if(r->next==NULL) break; r=r->next; } } } cout<<\"目录不存在\"<- 2 -

struct tm *newtime; char *tmpbuf=new char[120]; time_t lt; time(<); newtime=localtime(<); strftime(tmpbuf,128,\"%c\//showweizhi(); node *s; s=(node *)malloc(sizeof(node)); s=zhizhen->awenjian; node *s1; s1=(node *)malloc(sizeof(node)); //cout<<\"请输入文件的名称\"<>fname; //cout<<\"请输入文件的大小\"<>daxiao; strcpy(s1->name,fname); s1->daxiao=daxiao; s1->next=NULL; if(s==NULL) { zhizhen->awenjian=s1; s1->time=tmpbuf; // cout<<\"文件创建成功\"<name,fname)) { cout<<\"文件名字重复\"<next!=NULL) { if(!strcmp(s->next->name,fname)) {

cout<<\"文件名字重复\"<next; } s->next=s1; } int i,j,k; k=0; int i1=-1; int j1=-1; for(i=0;ibegin=i*lie+j+1; if(daxiao==1) { juzhen[i][j]=-1; s1->time=tmpbuf; return 0; } else { i1=i; j1=j; k++; continue; } } else { if(daxiao-k==1) { juzhen[i1][j1]=i*lie+j+1; juzhen[i][j]=-1;

- 3 -

s1->time=tmpbuf;

return 0; } juzhen[i1][j1]=i*lie+j+1; i1=i; j1=j; k++; } } } } s1->next=NULL; s1->time=tmpbuf; return 0; }

void wjgl::showweizhi() { cout.setf(3); char dizhi[20][10]; int i=0; int j; node1 *s; node1 *r; r=(node1 *)malloc(sizeof(node1)); s=(node1 *)malloc(sizeof(node1)); r=zhizhen; s=r->top; strcpy(dizhi[i],r->name); i++; //cout<name<<\"->\"; while(s!=NULL) { strcpy(dizhi[i],s->name); //cout<name<<\"->\"; s=s->top; i++; } for(j=i;j>0;j--) { cout<cout<<\":\\\\\"; else cout<<\"\\\\\"; } cout<<\">\"; }

int wjgl::rd() { showweizhi(); node1 *r; r=(node1 *)malloc(sizeof(node1)); r=zhizhen->amulu; cout<<\"输入要删除的目录的名字\"<>ming; if(r==NULL) { cout<<\"目录不存在\"<name,ming)) { if(r->amulu!=NULL||r->awenjian!=NULL) { cout<<\"目录不空不能删除\"<amulu=r->next; //cout<<\"删除成功\"<next!=NULL) { if(!strcmp(r->next->name,ming)) { if(r->next->amulu!=NULL||r->next->awenjian!=NULL)

- 4 -

{ cout<<\"目录不空不能删除\"<next=r->next->next; //cout<<\"删除成功\"<int wjgl::md() { struct tm *newtime; char *tmpbuf=new char[120]; time_t lt; time(<); newtime=localtime(<); strftime(tmpbuf,128,\"%c\ //showweizhi(); node1 *r; r=(node1 *)malloc(sizeof(node1)); r=zhizhen->amulu; char ming[20]; cin>>ming; if(r==NULL) { node1 *s; s=(node1 *)malloc(sizeof(node1)); s->time=tmpbuf; strcpy(s->name,ming); s->awenjian=NULL; s->amulu=NULL; s->next=NULL; s->top=zhizhen; zhizhen->amulu=s; } else if(!strcmp(r->name,ming)) { cout<<\"目录已经存在\"<} else { while(r->next!=NULL) { if(!strcmp(r->next->name,ming)) { cout<<\"目录已经存在 if(!strcmp(s->name,ming))

{ i=(s->begin-1)/lie; j=(s->begin-1)%lie; while(juzhen[i][j]!=-1) { temp=juzhen[i][j]; juzhen[i][j]=0; \"<next; } node1 *s; s=(node1 *)malloc(sizeof(node1)); s->time=tmpbuf; strcpy(s->name,ming); s->awenjian=NULL; s->amulu=NULL; s->next=NULL; s->top=zhizhen; r->next=s; }

// cout<<\"创建成功\"<int wjgl::del() { showweizhi(); node *s; s=(node *)malloc(sizeof(node)); s=zhizhen->awenjian;

// cout<<\"请输入文件的名称\"<>ming; int i,j; int temp; if(s==NULL) { cout<<\"删除不成功\"<i=(temp-1)/lie; j=(temp-1)%lie; } juzhen[i][j]=0; zhizhen->awenjian=s->next; cout<<\"删除成功\"<next!=NULL) { if(!strcmp(s->next->name,ming)) { i=(s->begin-1)/lie; j=(s->begin-1)%lie; while(juzhen[i][j]!=-1) { temp=juzhen[i][j]; juzhen[i][j]=0; i=(temp-1)/lie; j=(temp-1)%lie; } juzhen[i][j]=0; s->next=s->next->next; // cout<<\"删除成功\"<void wjgl::tree() { char c=getchar(); if(c==' ')

- 5 -

jiansuo(); else shuchu(zhizhen); }

void wjgl::showweishitu() { //cout.width(); int j,k; cout<<\"位\"<<\"示图为\"<void wjgl::shuchu(mulu *sc) { int i,j,k; i=0; j=0; k=0; mulu *r1; r1=(node1 *)malloc(sizeof(node1)); r1=zhizhen; mulu *r; r=(node1 *)malloc(sizeof(node1)); r=sc->amulu; cout<<\"

\"<<\". \"; showweizhi(); cout<top; if(zhizhen==NULL) ; else {cout<<\" \"<<\".. \"; showweizhi(); cout<- 6 -

zhizhen=r1;

while(r!=NULL) { i++; cout<time<<\"

\"<name<<\"

\"<<\" \"<next; } node *s; s=(node *)malloc(sizeof(node)); s=sc->awenjian; while(s!=NULL) { j++; k=k+s->daxiao; cout<time<<\" \"<name<<\" 大小\"<<\" \"<daxiao<<\" \"<<\" \"<next; } cout<<\"当前共有目录\"<void wjgl::jiansuo() { int k=0; int i=0; int j=0; char name[20];

// cout<<\"请输入名称\"<>name; int temp1=strlen(name); mulu *r;

r=(node1 *)malloc(sizeof(node1)); int wjgl::panduan(char a[], char b[]) r=zhizhen->amulu; { node *s; s=(node *)malloc(sizeof(node)); s=zhizhen->awenjian; while(r!=NULL) { if(panduan(name,r->name)==1) { i++; cout<time<<\" \"<name<<\"

\"<<\" \"; showweizhi(); cout<next; } while(s!=NULL) { if(panduan(name,s->name)==1) { j++; cout<time<<\" \"<name<<\" 大小 \"<daxiao<<\"

\"<<\" \"; k=k+s->daxiao; showweizhi(); cout<next; } cout<<\"目录\"<cout<<\"文件\"<\"<}

- 7 -

int biaoji=0; if(!strcmp(a,b)) return 1; int temp=strlen(a); int temp1=strlen(b); int i,j; for(i=0,j=0;iif(i==temp||j==temp1-1) break; } } if(a[i]=='?') { if(i==temp-1) {

if(j==temp1-1) return 1; else return 0; } } else if(a[i]==b[j]) continue; else return 0;

} if(i==temp&&j==temp1) return 1;

else return 0; return 0; return 1;*/ /*if(temp>temp1) }

#include #include\"wjgl.h\" using namespace std; void menu() { cout<<\"H-----------------help\"<int main() { wjgl awjgl; //menu(); while(1) { awjgl.showweizhi(); //cout<<\"请选择操作\"<>xuanxiang; if(!strcmp(xuanxiang,\"H\")||!strcmp(xuanxiang,\"h\")) { menu(); } if(!strcmp(xuanxiang,\"MD\")||!strcmp(xuanxiang,\"md\")) { awjgl.md(); } else if(!strcmp(xuanxiang,\"CD\")||!strcmp(xuanxiang,\"cd\")) { awjgl.cd(); } else if(!strcmp(xuanxiang,\"RD\")||!strcmp(xuanxiang,\"rd\")) { awjgl.rd();

- 8 -

} else if(!strcmp(xuanxiang,\"MK\")||!strcmp(xuanxiang,\"mk\")) { awjgl.mk(); } else if(!strcmp(xuanxiang,\"DEL\")||!strcmp(xuanxiang,\"del\")) { awjgl.del(); } else if(!strcmp(xuanxiang,\"DIR\")||!strcmp(xuanxiang,\"dir\")) { awjgl.tree(); } else if(!strcmp(xuanxiang,\"s\")||!strcmp(xuanxiang,\"S\")) { awjgl.showweishitu(); } else if(!strcmp(xuanxiang,\"E\")||!strcmp(xuanxiang,\"e\")) { return 0; } } return 0; }

实验步骤:1)两个CPP文件内容。

- 9 -

2)通过按H进入操作帮助提示。

- 10 -

3)通过按S查看位示图。

3)在目录文件中创建子目录mengji。

- 11 -

4)按CD从当前目录中换到已创建的mengji文件夹中,在mengji文件夹中再建一个20072411603文件夹,以及删除文件。

5)查看文件夹中的所有目录项。

- 12 -

6)退出

实验总结:通过这次实验在实验五和六的基础上,对操作系统文件管理的中查看位示图;在目录文件中创建子目录;根据当前目录切换到指定目录;搜索所要删除的目录是否为空目录,若是则删除;在当前目录中创建文件名称;搜索所要删除的文件是否存在,若是则删除;列出当前目录的所有目录项;退出程序等的操作方法有了一定的认识。

- 13 -

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务