zoukankan      html  css  js  c++  java
  • 文件遍历

    调用系统API

    #include <windows.h>
    #include <stdio.h>
    #include <string.h>
    #define LEN 1024
    
    void DirectoryList(LPCSTR Path)
    {
    	WIN32_FIND_DATA FindData;
    	HANDLE hError;
    	int FileCount = 0;
    	char FilePathName[LEN];
    	char FullPathName[LEN];
    	strcpy(FilePathName, Path);
    	strcat(FilePathName, "\\*.*");
    	hError = FindFirstFile(FilePathName, &FindData);
    	if (hError == INVALID_HANDLE_VALUE)
    	{
    		printf("搜索失败!");
    		return;
    	}
    	while(::FindNextFile(hError, &FindData))
    	{
    		if (strcmp(FindData.cFileName, ".") == 0 
    			|| strcmp(FindData.cFileName, "..") == 0 )
    		{
    			continue;
    		}
    
    		wsprintf(FullPathName, "%s\\%s", Path,FindData.cFileName);
    		FileCount++;
    		printf("\n%d  %s  ", FileCount, FullPathName);
    
    		if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    		{
    			printf("<Dir>");
    			DirectoryList(FullPathName);
    		}
    	}
    }
    
    int main()
    {
    	char path[LEN];
    	printf("please input the file Directory\n");
    	scanf("%s",path);
    	DirectoryList(path);
    }


  • 相关阅读:
    Meet Hadoop
    C++常用函数
    Summary
    获得小黄衫感想
    课程作业(八)
    课程作业(七)
    课程作业(六)
    课程作业(五)
    课程作业(四)
    课程作业(三)
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835258.html
Copyright © 2011-2022 走看看