zoukankan
html css js c++ java
vc遍历目录
#include
"
stdafx.h
"
#include
<
windows.h
>
#define FILEILTER
"
*.*
"
BOOL IsRoot(LPCTSTR lpszPath)
{
TCHAR szRoot[
4
];
wsprintf(szRoot,
"
%c:\\
"
, lpszPath[
0
]);
return
(lstrcmp(szRoot, lpszPath)
==
0
);
}
void
FindInAll(LPCTSTR lpszPath)
{
TCHAR szFind[MAX_PATH];
lstrcpy(szFind, lpszPath);
if
(
!
IsRoot(szFind))
lstrcat(szFind,
"
\\
"
);
lstrcat(szFind, FILEILTER);
//
找所有文件
WIN32_FIND_DATA wfd;
HANDLE hFind
=
FindFirstFile(szFind,
&
wfd);
if
(hFind
==
INVALID_HANDLE_VALUE)
//
如果没有找到或查找失败
return
;
do
{
if
(wfd.cFileName[
0
]
==
'
.
'
)
continue
;
//
过滤这两个目录
if
(wfd.dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY)
{
TCHAR szFile[MAX_PATH];
if
(IsRoot(lpszPath))
wsprintf(szFile,
"
%s%s
"
, lpszPath, wfd.cFileName);
else
{
wsprintf(szFile,
"
%s\\%s
"
, lpszPath, wfd.cFileName);
FindInAll(szFile);
//
如果找到的是目录,则进入此目录进行递归
}
}
else
{
TCHAR szFile[MAX_PATH];
if
(IsRoot(lpszPath))
{
wsprintf(szFile,
"
%s%s
"
, lpszPath, wfd.cFileName);
}
else
{
wsprintf(szFile,
"
%s\\%s
"
, lpszPath, wfd.cFileName);
printf(
"
%s\n
"
,szFile);
}
//
对文件进行操作
}
}
while
(FindNextFile(hFind,
&
wfd));
FindClose(hFind);
//
关闭查找句柄
}
int
main(
int
argc,
char
*
argv[])
{
FindInAll(
"
C:\\TEST
"
);
return
0
;
}
查看全文
相关阅读:
48. Rotate Image
83. Remove Duplicates from Sorted List
46. Permutations
HTML5笔记
18. 4Sum
24. Swap Nodes in Pairs
42. Trapping Rain Water
Python modf() 函数
Python min() 函数
Python max() 函数
原文地址:https://www.cnblogs.com/ahuo/p/1025197.html
最新文章
ZOJ 3713 In 7-bit
ZOJ 3710 Friends
ZOJ 3705 Applications
区间DP总结
HDU 1885 Key Task(BFS)
HDU 1866 A + B forever!
CodeForces 651 A Joysticks
Java实现 蓝桥杯 算法训练 Cowboys
Java实现 蓝桥杯 算法训练 Beaver's Calculator
Java实现 蓝桥杯 算法训练 Beaver's Calculator
热门文章
Java实现 蓝桥杯 算法训练 Beaver's Calculator
Java实现 蓝桥杯 算法训练 Lift and Throw
Java实现 蓝桥杯 算法训练 Lift and Throw
Java实现 蓝桥杯 算法训练 Lift and Throw
Java实现 蓝桥杯 算法训练 Airport Configuration
Java实现 蓝桥杯 算法训练 Airport Configuration
Java实现 蓝桥杯 算法训练 Airport Configuration
25. Reverse Nodes in k-Group
206. Reverse Linked List
23 Merged K sorted lists
Copyright © 2011-2022 走看看