程序1-1 列出目录中文件

#include "apue.h"
#include <dirent.h>

int main(int argc, char* argv[])
{
    DIR* dp;
    struct dirent* dirp;

    if (argc != 2)
        err_quit("usage: ls directory_name");

    if ((dp = opendir(argv[1])) == NULL)
    {
        err_sys("can‘t open %s", argv[1]);
    }
    while ((dirp = readdir(dp)) != NULL)
    {
        printf("%s\n", dirp->d_name);
    }

    closedir(dp);
    exit(0);
}

时间: 2024-08-27 09:45:57

程序1-1 列出目录中文件的相关文章

Python递归列出目录中文件脚本及其匿名函数

1.递归列出目录里的文件的脚本举例 列出目录中的文件可以通过下面方法:os.listdir() In [1]: import os In [4]: os.listdir('/root') Out[4]: ['.tcshrc', '.bash_history', '.bashrc', 'ENV', '.cache', '.config', '.cshrc', '.bash_logout', 'python', '.ssh', 'shell', '.bash_profile', '.ipython'

《Linux学习并不难》文件/目录管理(5): ls命令列出目录和文件信息

7.5  <Linux学习并不难>文件/目录管理(5): ls命令列出目录和文件信息 使用ls命令,对于目录而言将列出其中的所有子目录与文件信息:对于文件而言将输出其文件名以及所要求的其它信息.     命令语法: ls [选项] [目录|文件] 命令中各选项的含义如表所示. 选项 选项含义 -a 显示指定目录下所有子目录与文件,包括隐藏文件 -c 配合-lt:根据ctime 排序并显示ctime -d 如果参数是目录,只显示其名称而不显示其下的各文件和子目录 -F 显示文件类型 -i 在输出

C#统计目录中文件MD5值

1. [代码]统计目录中文件MD5值 using System.IO;using System.Security.Cryptography;using System.Collections;using System.Windows.Forms; IDataObject iData = Clipboard.GetDataObject();   if (iData.GetDataPresent(DataFormats.Text))   {string filepath=(string)iData.G

python工具程序一、复制目录中指定扩展名的文件

#!/usr/bin/env python # coding:utf-8 # xcopy Lib directory and rename all files to *d.lib import os from os.path import join,exists import shutil from win32com.shell import shell, shellcon from msvcrt import getch root_path = r"E:\workspace\Src"

Bash Shell 递归实现目录中文件拷贝

前言 今天工作中遇到了一个问题,如果将目录A中的文件拷贝到目录B中(前提目录B没有该文件),并保持文件在目录A的结构.项目重点如下: 需要在目录B中保持文件在目录A中的结构.假设A目录文件 A/test/1.txt,转移到目录B中应该是B/test/1.txt.同时还需要考虑目录B中是否存在test目录,多级目录就要考虑递归了.(还好,bash shell里写个目录递归遍历还是比较简单的.) 需要考虑A中文件是否在B中已经存在同名文件,如果存在,则不需要拷贝. 项目需求示例图如下: 实现 项目需

linux 只列出目录及文件

只列出目录: 1.  ls -F | grep '/$' 2.  ls -d */ 3.  ls -l | grep '^d' 4. find . -type d -maxdepth 1 只列出文件: ls -l |grep ^- |awk '{printf("%s\n ",$9)}'

递归法列出目录中的所有文件

用到的方法: import os os.listdir('/etc/'):列出指定目录下的所有文件和目录 os.path.isdir('/etc/'):判断是否是一个目录,返回一个布尔值 os.path.isfile('/etc/passwd'):判断是否是一个文件,返回一个布尔值 os.path.join('/etc','passwd'):连接两个路径 例: #!/usr/bin/python import sys import os def print_files(path): lsdir=

linux中文件/目录普通权限

权限 文件属性的查看############# ls -l filename/ls -ld dictionary-|rw-r--r--.|1| root| root|   46 |Oct  1 05:03 |filename- ---------  -  ----  ----    --  ------------  -------- 1    2         3    4      5      6      7             81."-":文件类型 -    ##普通

nginx 列出目录文件,提供下载最简单的实现方法

闲来无聊,学一下nginx的配置,简单的列出目录的文件,提供文件的下载 查看系统版本 [[email protected] nginx-1.7.9]# cat /etc/centos-release  CentOS release 6.5 (Final) 源码解压,-C指定解压的目录 [[email protected] nginx-1.7.9]tar -xvf  nginx-1.7.9.tar.gx -C /opt/ [[email protected] nginx-1.7.9]cd /opt