class LboxFileSystem

  オブジェクトの作成と削除



  
LboxDlg *Dlg;
LboxFileSystem *Fs;

LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message ) {
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			Fs = new LboxFileSystem( );
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Fs;
				delete Dlg;
			}
			break;
	}
	return FALSE;
}
  



  Size



  
// *********************************************************
// ファイルのサイズを取得( 4,294,967,295 ) 以内
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::Size( LboxString *LString, LPDWORD lpSize )
{
	return LboxFileSystem::Size(
		LString->szLboxString,
		lpSize
	);
}
BOOL LboxFileSystem::Size( LPCTSTR lpFileName, LPDWORD lpSize )
{
	HANDLE ret;
	WIN32_FIND_DATA wfd;

	ret = FindFirstFile(
		lpFileName,
		&wfd
	);
	if ( ret == INVALID_HANDLE_VALUE ) {
		return false;
	}
	FindClose( ret );

	*lpSize = wfd.nFileSizeLow;
	return true;
}
  



  DateUpdate

  
// *********************************************************
// ファイルの更新日付と時刻を文字列で取得( 9999/99/99 99:99:99 )
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::DateUpdate(
	LboxString *LstrFileName, LboxString *LString )
{
	if ( LString->nLboxString < 32 ) {
		LString->Resize( 32 );
	}
	return LboxFileSystem::DateUpdate(
		LstrFileName->szLboxString,
		LString->szLboxString
	);
}
BOOL LboxFileSystem::DateUpdate( LPCTSTR lpFileName, LPTSTR lpDateTime )
{
	HANDLE ret;
	WIN32_FIND_DATA wfd;

	ret = FindFirstFile(
		lpFileName,
		&wfd
	);
	if ( ret == INVALID_HANDLE_VALUE ) {
		return false;
	}
	FindClose( ret );

	FILETIME ft;
	SYSTEMTIME st;

	FileTimeToLocalFileTime( &(wfd.ftLastWriteTime), &ft );
	FileTimeToSystemTime( &ft, &st );
	wsprintf(
		lpDateTime,
		"%04d/%02d/%02d %02d:%02d:%02d",
		st.wYear,
		st.wMonth,
		st.wDay,
		st.wHour,
		st.wMinute,
		st.wSecond
	);

	return true;
}
  



  Copy

  
// *********************************************************
// ファイルのコピー
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::Copy( LboxString *LstrFile, LboxString *LstrNewFile )
{
	return LboxFileSystem::Copy(
		LstrFile->szLboxString,
		LstrNewFile->szLboxString
	);
}
BOOL LboxFileSystem::Copy( LPCTSTR lpFile, LPCTSTR lpNewFile )
{
	return CopyFile(
		lpFile,			// 既存のファイルの名前
		lpNewFile,		// 新しいファイルの名前
		false			// 上書き
	);
}
  



  ShellCopy

  
// *********************************************************
// エクスプローラのファイルコピー
// lpFiles に指定できるのは一つのファイルまたはディレクトリ
// lpNewFile に指定できるのは一つのファイルまたはディレクトリ
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::ShellCopy(
   HWND hWnd, LboxString *LstrFiles, LboxString *LstrNew )
{
	return LboxFileSystem::ShellCopy(
		hWnd,
		LstrFiles->szLboxString,
		LstrNew->szLboxString
	);
}
BOOL LboxFileSystem::ShellCopy( HWND hWnd, LPTSTR lpFiles, LPTSTR lpNew )
{
	SHFILEOPSTRUCT sf;

	lpFiles[lstrlen( lpFiles )+1] = 0x00;
	ZeroMemory( &sf, sizeof( sf ) );
	sf.hwnd = hWnd;
	sf.wFunc = FO_COPY;
	sf.pFrom = lpFiles;
	sf.pTo = lpNew;
	return (BOOL)!SHFileOperation( &sf );
}

// *********************************************************
// エクスプローラのファイルコピー
// lpNewFile に指定できるのは一つのディレクトリ
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::ShellCopy( HWND hWnd, HWND hList, LboxString *LstrDir )
{
	return LboxFileSystem::ShellCopy(
		hWnd,
		hList,
		LstrDir->szLboxString
	);
}
BOOL LboxFileSystem::ShellCopy( HWND hWnd, HWND hList, LPTSTR lpDir )
{
	LboxToken *Ltoken = new LboxToken( );

	LboxListCreateToken( hList, Ltoken );

	BOOL bRet;
	SHFILEOPSTRUCT sf;

	ZeroMemory( &sf, sizeof( sf ) );
	sf.hwnd = hWnd;
	sf.wFunc = FO_COPY;
	sf.pFrom = Ltoken->pszLboxToken;
	sf.pTo = lpDir;

	bRet = (BOOL)!SHFileOperation( &sf );

	delete Ltoken;
	return bRet;
}
  



  Exist

  
// *********************************************************
// ファイルの存在をチェック
// 戻り値 : 存在する true, 存在しない false
// *********************************************************
BOOL LboxFileSystem::Exist( LboxString *LString )
{
	return LboxFileSystem::Exist( LString->szLboxString );
}
BOOL LboxFileSystem::Exist( LPCTSTR lpFile )
{
	return PathFileExists(
		lpFile
	);
}
  



  IsDirectory

  
// *********************************************************
// ディレクトリかどうかチェックする
// 戻り値 : ディレクトリ true, 以外 false
// *********************************************************
BOOL LboxFileSystem::IsDirectory( LboxString *LString )
{
	return LboxFileSystem::IsDirectory( LString->szLboxString );
}
BOOL LboxFileSystem::IsDirectory( LPCTSTR lpPath )
{
	return PathIsDirectory(
		lpPath
	);
}
  



  ChangeDirectory

  
// *********************************************************
// カレントディレクトリ変更
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::ChangeDirectory( LboxString *LString )
{
	return LboxFileSystem::ChangeDirectory(
		LString->szLboxString
	);
}
BOOL LboxFileSystem::ChangeDirectory( LPCTSTR lpPath )
{
	return SetCurrentDirectory(
		lpPath
	);
}
  



  GetShortPathName

  
// *********************************************************
// 長い名前から短い名前を取得する
// " で囲まれていたら事前に取り去る
// 引数のデータはコピーして使用するので影響を受けない
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::GetShortPathName(
 LboxString *LstrLongPath, LboxString *LstrShortPath, int nSize )
{
	LstrShortPath->Resize( MAX_PATH );
	return LboxFileSystem::GetShortPathName(
		LstrLongPath->szLboxString,
		LstrShortPath->szLboxString,
		LstrShortPath->nLboxString
	);
}
BOOL LboxFileSystem::GetShortPathName(
 LPTSTR lpLongPath, LPTSTR lpShortPath, int nSize )
{
	BOOL bRet;
	DWORD	nRequiredBufferSize;

	char *szPath = new char[lstrlen( lpLongPath ) + 10];
	lstrcpy( szPath, lpLongPath );
	LboxStringRemoveEnclose( szPath, '"' );

	lpShortPath[0] = 0x00;
	nRequiredBufferSize = ::GetShortPathName(
		szPath,
		lpShortPath,
		(DWORD)nSize
	);
	if ( lpShortPath[0] == 0x00 ) {
		bRet = false;
	}
	if ( nRequiredBufferSize > (DWORD)nSize ) {
		bRet = false;
	}
	bRet = true;

	delete [] szPath;
	return bRet;
}
  



  ShellDelete

  
// *********************************************************
// エクスプローラのファイル削除( ディレクトリ可 )
// lpFiles に指定できるのは一つのファイルまたはディレクトリ
// lpFiles がフルパスで指定されているとゴミ箱へ移動
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::ShellDelete( HWND hWnd, LboxString *LstrFiles )
{
	return LboxFileSystem::ShellDelete(
		hWnd,
		LstrFiles->szLboxString
	);
}
BOOL LboxFileSystem::ShellDelete( HWND hWnd, LPTSTR lpFiles )
{
	SHFILEOPSTRUCT sf;

	lpFiles[lstrlen( lpFiles )+1] = 0x00;
	ZeroMemory( &sf, sizeof( sf ) );
	sf.hwnd = hWnd;
	sf.wFunc = FO_DELETE;
	sf.pFrom = lpFiles;
	sf.fFlags = FOF_ALLOWUNDO;
	return (BOOL)!SHFileOperation( &sf );
}

// *********************************************************
// エクスプローラのファイル削除( ディレクトリ可 )
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::ShellDelete( HWND hWnd, HWND hList )
{
	LboxToken *Ltoken = new LboxToken( );

	LboxListCreateToken( hList, Ltoken );

	BOOL bRet;
	SHFILEOPSTRUCT sf;

	ZeroMemory( &sf, sizeof( sf ) );
	sf.hwnd = hWnd;
	sf.wFunc = FO_DELETE;
	sf.pFrom = Ltoken->pszLboxToken;
	sf.fFlags = FOF_ALLOWUNDO;

	bRet = (BOOL)!SHFileOperation( &sf );

	delete Ltoken;
	return bRet;
}
  



  SmallIconIndex

  
// *********************************************************
// 小さいアイコンのシステムイメージリスト上の番号を取得
// 戻り値 : インデックス
// *********************************************************
int LboxFileSystem::SmallIconIndex( LboxString *LString )
{
	return LboxFileSystem::SmallIconIndex( LString->szLboxString );
}
int LboxFileSystem::SmallIconIndex( LPCTSTR lpName )
{
	SHFILEINFO sfi;

	SHGetFileInfo(
		lpName,
		NULL,
		&sfi,
		sizeof( SHFILEINFO ),
		SHGFI_ICON | SHGFI_SMALLICON   
	);

	return sfi.iIcon;
}
  



  CreateTempFile

  
// *********************************************************
// テンポラリファイル作成 ( .tmp )
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::CreateTempFile(
	LboxString *LPath, LPTSTR lpPrefix, LboxString *LString
)
{
	return LboxFileSystem::CreateTempFile(
		LPath->szLboxString,
		lpPrefix,
		LString
	);
}
BOOL LboxFileSystem::CreateTempFile(
	LPTSTR lpCreatePath, LPTSTR lpPrefix, LboxString *LString
)
{
	UINT nRet;

	if ( LString->nLboxString < MAX_PATH ) {
		LString->Resize( MAX_PATH );
	}
	nRet = GetTempFileName(
		lpCreatePath,
		lpPrefix,
		0,
		LString->szLboxString
	);

	if ( nRet == 0 ) {
		return false;
	}

	return true;
}
  



  CreateDirectory

  
// *********************************************************
// ディレクトリ作成 ( デフォルトセキュリティ )
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::CreateDirectory( LboxString *LPath )
{
	return LboxFileSystem::CreateDirectory(
		LPath->szLboxString
	);
}
BOOL LboxFileSystem::CreateDirectory( LPTSTR lpPath )
{
	return ::CreateDirectory( lpPath, NULL );
}
  



  Rename

同一ドライブ内の移動も行います

  
// *********************************************************
// 名称変更
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxFileSystem::Rename( LboxString *LPath, LboxString *LnewPath )
{
	return LboxFileSystem::Rename(
		LPath->szLboxString,
		LnewPath->szLboxString
	);
}
BOOL LboxFileSystem::Rename( LPTSTR lpPath, LPTSTR lpNewPath )
{
	return ::MoveFile( lpPath, lpNewPath );
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ