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;
    }
    
  • 相关阅读:
    我罗斯方块最终篇
    我罗斯汇报作业一
    11组-Alpha冲刺-2/6
    11组-Alpha冲刺-1/6
    结对编程作业
    11组 团队展示
    第一次个人编程作业
    第一次博客作业
    寒假作业3
    寒假作业2
  • 原文地址:https://www.cnblogs.com/retry/p/10007818.html
Copyright © 2011-2022 走看看