ホーム » gcc » EnumFilesTree で無限ループ

2017年3月
 1234
567891011
12131415161718
19202122232425
262728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,317 アクセス



EnumFilesTree で無限ループ

フォルダ以下の全てのファイルを列挙する関数

v_tstring	EnumFilesTree	(LPCTSTR path)
{
	v_tstring	foundFiles = ::EnumFiles(path) ;
	v_tstring	foundFolds = ::ExtractFolders(foundFiles) ;
	for (size_t index=0 ; index<foundFolds.size() ; index++) {
		tstring		subFold = foundFolds[index] ;
		v_tstring	chFiles = ::EnumFiles(subFold.c_str()) ;
		v_tstring	chFolds = ::ExtractFolders(chFiles) ;
		foundFolds.insert(foundFolds.end(),chFolds.begin(),chFolds.end()) ;
		foundFiles.insert(foundFiles.end(),chFiles.begin(),chFiles.end()) ;
		}
	return	foundFiles ;
	}

今まで特に問題なく動作していたが,
先週末 VC 14 i3DV のデバッグ版を実行すると無限ループに.
Release 版や,VC 12 のデバッグ版などでは OK .


昨日は,別の PC 環境だったため再現せず.


今日デバッガを使用して調査すると,
 フォルダの「作成日時」が正しくない.
 /wordpress/dev/2016/09/15/
そのため,_wstat64 が正しく帰ってこない.


v_tstring	EnumFiles	(LPCTSTR path_,const bool skipDot=true)
{
	tstring	path = ::Path_DelLastSP(path_) ;
	if (!File_IsDirectory(path.c_str()))	{
		path = ::Path_GetDir(path) ;
		}
	v_tstring	foundFiles ;
	#if		defined	__GNUC__
		foundFiles = ::EnumFiles_GNUC	(path,skipDot) ;
	#elif	defined	_MFC_VER
		foundFiles = ::EnumFiles_MFC	(path,skipDot) ;
	#elif	defined	_MSC_VER
		foundFiles = ::EnumFiles_MSC	(path,skipDot) ;
	#endif
	return	foundFiles ;
	}

ここの,File_IsDirectory(…) で,stat を利用している.


次の様に ::GetFileAttributes(…) の判断を追加.

	if (!::File_IsDirectory(path.c_str()))	{
		#if	(_MSC_VER == 1900)
		{
			if (!::FA_Is_Directory(path)) {
				path = ::Path_GetDir(path) ;
				}
			}
		#else
		{
			path = ::Path_GetDir(path) ;
			}
		#endif
		}

enumfile.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。