文件和目录的操作函数实例
/* ************************************************************************ * Filename: FileManager.c * Description: * Version: 1.0 * Created: 2010年08月21日 13时10分34秒 * Revision: none * Compiler: gcc * Author: chengbin_liu * Company: * ************************************************************************/ #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <dirent.h> #include <sys/stat.h> #include <sys/dir.h> #define SIZE 100 //================================================================================ void welcome() { printf("**********************************************************\n"); printf("\tmainmenu\n"); printf("\t1,tree-display\n"); printf("\t2,tree-creat\n"); printf("\t3,file-create/open\n"); printf("\t4,tree-open\n"); printf("\t5,tree-back\n"); printf("\t6,tree/file-copy\n"); printf("\t7,tree/file-paste\n"); printf("\t8,tree-delete\n"); printf("\t9,file-delete\n"); printf("\t10,tree/file-property\n"); printf("\t11,tree/file-rename\n"); printf("\t12,tree/file-changesize\n"); printf("\t13,end\n"); printf("************************************************************\n"); } //============================================================================= //show directory void treedisplay() { DIR *dir; char buf[SIZE]; struct dirent *ent; getcwd(buf,SIZE); dir=opendir(buf); while((ent=readdir(dir))!=NULL) puts(ent->d_name); closedir(dir); } //============================================================================ //create the directory 拥有帝国一切,皆有可能。欢迎访问phome.net void treecreate() { int fd; char pathname[SIZE]; do { printf("new tree=="); scanf("%s",pathname); fd=mkdir(pathname,O_CREAT); if(fd==-1) { perror("create failed,try again!\n"); } else { chmod(pathname,0761); printf("create successizes!\n"); } }while(fd==-1); } //============================================================================= void fileread(char pathname[]) { char ch; FILE *fp; fp=fopen(pathname,"r"); ch=fgetc(fp); while(ch!=EOF) { putchar(ch); ch=fgetc(fp); } fclose(fp); } //============================================================================ void filewrite(char pathname[]) { char ch; FILE *fp; long where; fp=fopen(pathname,"rb "); printf("input the where of write=="); scanf("%ld",&where); fseek(fp,where,SEEK_SET); printf("# for the EOF,begin :\n"); ch=getchar(); while(ch!='' |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |