⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydir.c

📁 在Linux下实现文件的拷贝
💻 C
字号:
#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <time.h>#include <string.h>struct fileinfo{  char * tiaomu;  struct fileinfo *next;};struct fileinfo * list(char *);void printout(char *,char *);void printout(char *dir,char *name){    int i,j;    char perms[10];    struct stat sbuf;    char newname[1024];    sprintf(newname,"%s/%s",dir,name);    stat(newname,&sbuf);    printf("%5d KB",(sbuf.st_size+1024-1)/1024);    printf("%3d个(uid)%5d(gid)%5d",sbuf.st_nlink,sbuf.st_uid,sbuf.st_gid);    printf("(size)%7d%.20s",sbuf.st_size,ctime(&sbuf.st_mtime));    printf("%s\n",name);}struct fileinfo * list(char * name){    DIR *dp;    struct dirent *dir;    struct fileinfo *dir_node;    struct fileinfo *head=NULL;    if((dp=opendir(name))==NULL)                sprintf(stderr,"%s:cannt open.\n",name);    while((dir=readdir(dp))!=NULL)          {       dir_node = (struct fileinfo *)malloc(sizeof(struct fileinfo));       dir_node -> tiaomu = dir -> d_name;       dir_node -> next = head;       head = dir_node;       printout(name,dir->d_name);          }    close(dp);    return head;}int main(int argc,char *argv[]){ DIR *dirp; struct dirent *direntp; struct stat statbuf; struct fileinfo * test,*headp; if(stat(argv[1],&statbuf)<0)        perror(argv[1]);  if((statbuf.st_mode&S_IFMT)==S_IFDIR)        test=list(argv[1]); else   printout(".",argv[1]);   for(headp=test;headp!=NULL;headp=headp->next)       puts(headp->tiaomu); return 0;}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -