文件和目录的操作函数实例
#'')
{ fwrite(&ch,1,1,fp); ch=getchar(); } fclose(fp); }
//============================================================================ //open the file and readwrite void filecreateopen() { int fd; char choose, pathname[SIZE]; printf("new/open=="); scanf("%s",pathname); fd=open(pathname,O_CREAT | O_APPEND | O_RDWR); if(fd==-1) { perror("file create/open failed,try again.....\n"); close(fd); exit(1); } else { chmod(pathname,0761); printf("file create/open success!\n"); fileread(pathname); } printf("\ninput the text? (y/n)"); 拥有帝国一切,皆有可能。欢迎访问phome.net scanf("%c",&choose); scanf("%c",&choose); if(choose==''y'') filewrite(pathname); fileread(pathname); printf("\n"); close(fd); } //============================================================================ //============================================================================= //change the current directory void treeopen() { int fd; char pathname[SIZE],buf[SIZE]; system("ls -l"); printf("open tree=="); scanf("%s",pathname); fd=chdir(pathname); if(fd==-1) { perror("tree open failed ,try again..."); close(fd); return; } else { system("ls -l"); getcwd(buf,SIZE); printf("%s\n",buf); printf("tree open ok..\n"); } } //============================================================================= //turn back previous directory void treeback() { char buf[SIZE]; chdir(".."); system("ls -l"); getcwd(buf,SIZE); printf("%s\n",buf); } //============================================================================= //copy operation long treefilecopy(char copybuf[],char copyname[]) { int fd; struct stat buf; long size; system("ls -l"); printf("copy file /tree==");scanf("%s",copyname); fd=open(copyname,O_RDONLY); if(fd==-1) { perror("failed ,try again!.."); return 0; } else stat(copyname,&buf); size=buf.st_size; read(fd,copybuf,size); return size; } //============================================================================ //paste operation void treefilepaste(int len,char pastebuf[],char copyname[]) { int fd; 拥有帝国一切,皆有可能。欢迎访问phome.netchar pastename[]={"re-"}; strcat(pastename,copyname); fd=open(pastename,O_CREAT| O_APPEND|O_RDWR); if(fd==-1) { perror("failed ,try again.."); return; } write(fd,pastebuf,len); system("ls -l"); }
//============================================================================= //delete the directory void treedelete() { int fd; char pathname[SIZE]; system("ls - |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |