zoukankan      html  css  js  c++  java
  • 文件目录操作opendir、readdir

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/un.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <netinet/in.h>
    #include <dirent.h>
    #include <arpa/inet.h>
    #include <sys/stat.h>
    #include <sys/wait.h>
    #include <signal.h>
    #include <pthread.h>
    #include <semaphore.h>
    #include <errno.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <string.h>
    
    int FileNameScan(char *pcPath)
    {
    
    	DIR             *pFile      = NULL;        //打开目录返回的指针
    	struct dirent   *psDirInfo  = NULL;        //读取目录返回的结构图指针
    	unsigned char    iRetValue;
    	pFile = opendir(pcPath);             //打开目录
    	if(NULL == pFile)
    	{
    	    printf("DevXmlAnalysis.c: %s is not exist!
    ", pcPath);
    		return -1;			//如果目录为空,返回-1
    	}
        else 
    	{
    	 /*
    		1、也就是说readdir每调用一次,pcPath目录中的文件就重新扫描另1个
    		2、至于扫描顺序这里暂且不研究
    	 */
    		while(NULL != (psDirInfo = readdir(pFile))) 
    		{
    			iRetValue = strlen(psDirInfo -> d_name);
    			
    			printf("file length = %d,file name is %s
    
    ",iRetValue,psDirInfo -> d_name);
    		}
    	}
    	
    	
    	closedir(pFile);
    
    	return 0;
    }
    int main()
    {
    
    	FileNameScan("./");
    	return 0;
    }
    
  • 相关阅读:
    python编码的那些事
    算法基础与排序
    排序算法之low B三人组
    Django之反向生成url
    ipython的用法详解
    python3的zip函数
    Django中url的生成过程详解
    Django的ORM实现数据库事务操作
    Django的admin.py注册流程
    Django跨域请求之JSONP和CORS
  • 原文地址:https://www.cnblogs.com/retry/p/10007818.html
Copyright © 2011-2022 走看看