| 
              【只显示文件夹】// ExploreFolder.cpp : Defines the entry point for the console application.
 //
 
 #include "stdafx.h"
 #include <Windows.h>
 
 #define echo(str) WriteConsole(hConsoleOutput, str, _tcslen(str), NULL, NULL)
 #define echo_t(str) echo(TEXT(str))
 
 HANDLE hConsoleOutput;
 
 BOOL explore(LPTSTR szFolder, UINT indent = 0)
 {
 TCHAR szFileName[MAX_PATH];
 TCHAR szNextFolder[MAX_PATH];
 _tcscpy_s(szFileName, szFolder);
 _tcscat_s(szFileName, TEXT("\\*"));
 
 WIN32_FIND_DATA ffd;
 HANDLE hFindFile = FindFirstFile(szFileName, &ffd);
 if (hFindFile == INVALID_HANDLE_VALUE)
 return FALSE;
 
 UINT i;
 do
 {
 if (ffd.cFileName[0] == '.')
 continue;
 if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
 continue;
 
 // 缩进
 i = indent;
 while (i--)
 echo_t("--");
 
 // 输出文件或文件夹的名称
 echo(ffd.cFileName);
 echo_t("\r\n");
 
 // 递归遍历子文件夹
 _tcscpy_s(szNextFolder, szFolder);
 _tcscat_s(szNextFolder, TEXT("\\"));
 _tcscat_s(szNextFolder, ffd.cFileName);
 explore(szNextFolder, indent + 1);
 } while (FindNextFile(hFindFile, &ffd));
 
 FindClose(hFindFile);
 return TRUE;
 }
 
 int _tmain(int argc, _TCHAR* argv[])
 {
 hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
 explore(TEXT("C:\\inetpub"));
 return 0;
 }
 【输出】
 AdminScripts
 --0404
 --0409
 --0804
 --0C0A
 custerr
 --en-US
 --es-ES
 --zh-CN
 --zh-TW
 ftproot
 history
 logs
 --FailedReqLogFiles
 --LogFiles
 ----W3SVC1
 --wmsvc
 temp
 --appPools
 --ASP Compiled Templates
 --IIS Temporary Compressed Files
 wwwroot
 --aspnet_client
 ----system_web
 ------2_0_50727
 ------4_0_30319
 --aspx
 Press any key to continue . . .
 |