フォルダを削除する。
BOOL xxxxxx::DeleteFolder(LPCTSTR loFolder)
{
CFileFind fFind;
CString strFolderPath = loFolder;
strFolderPath.TrimRight( _T("\\") );
strFolderPath += _T("\\*.*");
if( !fFind.FindFile( strFolderPath ) )
return FALSE;
BOOL bRet = TRUE;
while( bRet ){
bRet = fFind.FindNextFileW();
if( fFind.IsDots() )
continue;
CString strPath;
strPath.Format( _T("%s\\%s"), loFolder, fFind.GetFileName() );
if( fFind.IsDirectory() )
DeleteItem( strPath );
else
DeleteFile( strPath );
}
fFind.Close();
return RemoveDirectory( loFolder );
}
BOOL xxxxxx::DeleteFolder(LPCTSTR loFolder)
{
CFileFind fFind;
CString strFolderPath = loFolder;
strFolderPath.TrimRight( _T("\\") );
strFolderPath += _T("\\*.*");
if( !fFind.FindFile( strFolderPath ) )
return FALSE;
BOOL bRet = TRUE;
while( bRet ){
bRet = fFind.FindNextFileW();
if( fFind.IsDots() )
continue;
CString strPath;
strPath.Format( _T("%s\\%s"), loFolder, fFind.GetFileName() );
if( fFind.IsDirectory() )
DeleteItem( strPath );
else
DeleteFile( strPath );
}
fFind.Close();
return RemoveDirectory( loFolder );
}
PR
ファイルをコピーする。
BOOL xxxxxx::CopyAll(LPCTSTR OldFolder, LPCTSTR NewFolder)
{
CFileFind FileFind;
CString Str;
Str.Format( _T("%s\\*.*"), OldFolder );
FileFind.FindFile( Str, 0 );
while( FileFind.FindNextFile() != 0 ){
if( FileFind.IsDots() != 0 ){ continue; }
CString Name= FileFind.GetFileName();
CString Dst;
Dst.Format( _T("%s\\%s"), NewFolder, Name );
CopyFile( FileFind.GetFilePath(), Dst, FALSE );
}
return TRUE;
}
BOOL xxxxxx::CopyAll(LPCTSTR OldFolder, LPCTSTR NewFolder)
{
CFileFind FileFind;
CString Str;
Str.Format( _T("%s\\*.*"), OldFolder );
FileFind.FindFile( Str, 0 );
while( FileFind.FindNextFile() != 0 ){
if( FileFind.IsDots() != 0 ){ continue; }
CString Name= FileFind.GetFileName();
CString Dst;
Dst.Format( _T("%s\\%s"), NewFolder, Name );
CopyFile( FileFind.GetFilePath(), Dst, FALSE );
}
return TRUE;
}
ファイルサイズを取得する。
DWORD xxxxxx::GetFileSize(CString strFileName)
{
CLASS_MAKE_UTILS;
DWORD dwFileSize;
HANDLE hFind;
WIN32_FIND_DATA file;
hFind = FindFirstFileW( (LPCWSTR)( strFileName ), &file );
if( hFind != INVALID_HANDLE_VALUE ){
dwFileSize = file.nFileSizeHigh * MAXDWORD + file.nFileSizeLow;
FindClose( hFind );
} else {
dwFileSize = -1;
}
return dwFileSize / 1024 / 1024 +1;
}
DWORD xxxxxx::GetFileSize(CString strFileName)
{
CLASS_MAKE_UTILS;
DWORD dwFileSize;
HANDLE hFind;
WIN32_FIND_DATA file;
hFind = FindFirstFileW( (LPCWSTR)( strFileName ), &file );
if( hFind != INVALID_HANDLE_VALUE ){
dwFileSize = file.nFileSizeHigh * MAXDWORD + file.nFileSizeLow;
FindClose( hFind );
} else {
dwFileSize = -1;
}
return dwFileSize / 1024 / 1024 +1;
}
テキストファイルを読込
void xxxxxx::GetTextData(CString strFilePath, CStringArray& strArrTextData)
{
// パラメータ格納データ
char buf[1000];
CString strBuf;
CString str;
// ファイル読込み
CStdioFile fin;
int curPos = 0;
if( !fin.Open( strFilePath, CFile::modeRead | CFile::typeText) ){
CString error;
error.Format(_T("Error Read File %s"), strFilePath );
::AfxMessageBox(error);
return;
}
CString strW;
while( fin.ReadString( strW ) ){
CStringW strBufW = strBuf;
strArrTextData.Add( strW );
}
_wsetlocale(LC_ALL, _T(""));
}
void xxxxxx::GetTextData(CString strFilePath, CStringArray& strArrTextData)
{
// パラメータ格納データ
char buf[1000];
CString strBuf;
CString str;
// ファイル読込み
CStdioFile fin;
int curPos = 0;
if( !fin.Open( strFilePath, CFile::modeRead | CFile::typeText) ){
CString error;
error.Format(_T("Error Read File %s"), strFilePath );
::AfxMessageBox(error);
return;
}
CString strW;
while( fin.ReadString( strW ) ){
CStringW strBufW = strBuf;
strArrTextData.Add( strW );
}
_wsetlocale(LC_ALL, _T(""));
}