UNIX/Linux系统命令(2)——目录操作

chdir/fchdir/getcwd

 
  char *getcwd(char *buf, size_t size);
  功能:获取当前进程的工作目录,工作目录是指当不加路径信息时,创建/打开时从那个目录下查找,
工作目录默认是程序所在的目录
   int chdir(const char *path);
   功能:修改进程的工作目录
   返回值:成功返回0,失败返回-1  
   
   int fchdir(int fd);
   功能:修改进程的工作目录
   fd:被open打开的目录文件的fd
   返回值:成功返回0,失败返回-1
 

opendir/fdopendir/closedir/readdir/rewinddir/telldir/seekdir

    #include <dirent.h>
    DIR *opendir(const char *name);
    功能:打开一个目录流
    返回值:目录流(链表)
    
    DIR *fdopendir(int fd);
    功能:使用文件描述符获取目录流,fd必须是目录文件的
    
    int closedir(DIR *dirp);
    功能:关闭目录流
    
    struct dirent *readdir(DIR *dirp);
    功能:从目录流中读取一个文件节点信息
    struct dirent {
               ino_t          d_ino;       /* inode number */i节点号
               off_t          d_off;       /* offset to the next dirent */下一个文件结点信息的偏移量
               unsigned short d_reclen;    /* length of this record */当前文件结点信息的长度
               unsigned char  d_type;      /* type of file; not supported by all file system types */文件类型
               char           d_name[256]; /* filename */文件名字
                  };
       DT_CHR      This is a character device.
       DT_DIR      This is a directory.
       DT_FIFO     This is a named pipe (FIFO).
       DT_LNK      This is a symbolic link.
       DT_REG      This is a regular file.
       DT_SOCK     This is a UNIX domain socket.
       DT_UNKNOWN  The file type is unknown.
    
    int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
    void rewinddir(DIR *dirp);
    功能:把目录流的位置指针调整到开头
    
    long telldir(DIR *dirp);
    功能:获取当前目录流的位置指针在第几结点
    
    void seekdir(DIR *dirp, long offset);
    功能:调整当前目录流的位置指针
    offer:根据当前位置指针进行偏移
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值