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;
    }
    
  • 相关阅读:
    zip
    sublime 3 注册码
    css3 文本控制自动换行
    ST3 package control
    cf1139D-Steps to One
    2019-2020 ACM-ICPC, Asia Xuzhou Regional Contest
    2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest
    Tree
    B
    多源对多源最短路
  • 原文地址:https://www.cnblogs.com/retry/p/10007818.html
Copyright © 2011-2022 走看看