public static void EnumFile(string strPath, ON_WALK_FILE fnWalk, bool isGetFile = false) { if (strPath == null) { return; } DirectoryInfo kDI = new DirectoryInfo(strPath); ForEnumFile(kDI, fnWalk, isGetFile); }
private static void ForEnumFile(FileSystemInfo info, ON_WALK_FILE fnWalk, bool isGetFile = false) { if (!info.Exists) { return; } DirectoryInfo dir = info as DirectoryInfo; //不是目录 if (dir == null) { return; } int i; FileInfo file; FileSystemInfo[] files = dir.GetFileSystemInfos(); for (i = 0; i < files.Length; i++) { file = files[i] as FileInfo; //是文件 if (file != null) { if (fnWalk != null) { fnWalk(file.FullName); } } else { if (isGetFile) { if (fnWalk != null) { fnWalk(files[i].FullName); } } ForEnumFile(files[i], fnWalk, isGetFile); } } }