CFile

  ファイルとパスの存在チェック



  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::FileExists(BSTR PathString,BOOL *pVal)
{

	USES_CONVERSION;
	LPTSTR szPathString = OLE2T(PathString);

	*pVal = PathFileExists( szPathString );

	return S_OK;
}
  

>implemented in Shlwapi.dll and defined in [Shlwapi.h] and [Shlwapi.lib]
とありますが、VC++6.0 の COM 作成では、Shlwapi.h は必要ありませんでした。



  パスを取り去る



  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::StripPath(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N];

	PathStripPath( szBaseString );
	lstrcpy( lpBuffer, szBaseString );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  

#define BUFFER_N 2
を定義しています。



  ファイル名部分を取り去る

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::RemoveFileSpec(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N];

	PathRemoveFileSpec( szBaseString );
	lstrcpy( lpBuffer, szBaseString );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  カレントディレクトリの取得

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::GetCurDir(BSTR *pVal)
{
	char	Dummy[2];
	DWORD	nRequiredBufferSize;

	nRequiredBufferSize = GetCurrentDirectory( (DWORD)1, Dummy );
 
	char *lpBuffer = new char[(nRequiredBufferSize + 2)*BUFFER_N];
	nRequiredBufferSize++;
	GetCurrentDirectory( nRequiredBufferSize, lpBuffer );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  カレントディレクトリの設定

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::SetCurDir(BSTR DirPath, BOOL *pVal)
{

	USES_CONVERSION;
	LPTSTR szDirPath = OLE2T(DirPath);

	*pVal = SetCurrentDirectory( szDirPath );
	return S_OK;
}
  



  長い名前 --> 短い名前

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::ShortPathName(BSTR LongPathName, BSTR *pVal)
{

	char	Dummy[2];
	DWORD	nRequiredBufferSize;

	USES_CONVERSION;
	LPTSTR szLongPathName = OLE2T(LongPathName);
	nRequiredBufferSize = GetShortPathName( szLongPathName, Dummy, (DWORD)1 );
 
	char *lpBuffer = new char[(nRequiredBufferSize + 2)*BUFFER_N];
	nRequiredBufferSize++;
	GetShortPathName( szLongPathName, lpBuffer, nRequiredBufferSize );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  短い名前 --> 長い名前

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::LongPathName(BSTR ShortPathName, BSTR *pVal)
{

	if ( GetPlatform() < 1 ) {
		*pVal = A2BSTR("error	Windows95 Unsupported");
		return S_OK;
	}

	char	Dummy[2];
	DWORD	nRequiredBufferSize;

	USES_CONVERSION;
	LPTSTR szShortPathName = OLE2T(ShortPathName);
	nRequiredBufferSize = GetLongPathName( szShortPathName, Dummy, (DWORD)1 );
 
	char *lpBuffer = new char[(nRequiredBufferSize + 2)*BUFFER_N];
	nRequiredBufferSize++;
	GetLongPathName( szShortPathName, lpBuffer, nRequiredBufferSize );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  拡張子削除

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::RemoveExtension(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N];

	PathRemoveExtension( szBaseString );
	lstrcpy( lpBuffer, szBaseString );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  文字列最後尾の \ 削除

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::RemoveBackslash(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N];

	PathRemoveBackslash( szBaseString );
	lstrcpy( lpBuffer, szBaseString );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;


	return S_OK;
}
  



  CopyFile

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::Win32CopyFile(BSTR Sfile, BSTR Dfile, BOOL Exist, BOOL *pVal)
{
	USES_CONVERSION;
	LPTSTR szSfile = OLE2T(Sfile);
	LPTSTR szDfile = OLE2T(Dfile);

	BOOL ret;

	ret = CopyFile( szSfile, szDfile, Exist );

	*pVal = ret;

	return S_OK;
}
  



  文字列最後尾の \ 削除

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::RemoveBackslash(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N];

	PathRemoveBackslash( szBaseString );
	lstrcpy( lpBuffer, szBaseString );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  CreateDirectory

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::Win32CreateDirectory(BSTR DirString, BOOL *pVal)
{
	USES_CONVERSION;
	LPTSTR szDirString = OLE2T(DirString);

	BOOL ret;

	ret = CreateDirectory( szDirString, NULL );

	*pVal = ret;

	return S_OK;
}
  



  文字列最後尾の \ 追加

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::AddBackslash(BSTR BaseString, BSTR *pVal)
{
	USES_CONVERSION;
	LPTSTR szBaseString = OLE2T(BaseString);

	char *lpBuffer = new char[lstrlen(szBaseString)*BUFFER_N+10];

	lstrcpy( lpBuffer, szBaseString );
	PathAddBackslash( lpBuffer );

	*pVal = A2BSTR(lpBuffer);
	delete [] lpBuffer;

	return S_OK;
}
  



  ディレクトリ削除

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::Win32RemoveDirectory(BSTR TargetPath, BOOL *pVal)
{
	USES_CONVERSION;
	LPTSTR szDirString = OLE2T(TargetPath);

	BOOL ret;

	ret = RemoveDirectory( szDirString );

	*pVal = ret;

	return S_OK;
}
  



  ファイル削除

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::Win32DeleteFile(BSTR TargetPath, BOOL *pVal)
{
	USES_CONVERSION;
	LPTSTR szDirString = OLE2T(TargetPath);

	BOOL ret;

	ret = DeleteFile( szDirString );

	*pVal = ret;

	return S_OK;
}
  



  ファイルサイズ取得

  
//*******************************************************************
// ( winbase.h : kernel32.lib )
//*******************************************************************
STDMETHODIMP CFile::FileSize(BSTR TargetPath, LONG *pVal)
{
	USES_CONVERSION;
	LPTSTR szTargetPath = OLE2T(TargetPath);

	HANDLE				handle;
	WIN32_FIND_DATA		FindFileData;

	handle = FindFirstFile( szTargetPath, &FindFileData );
	if ( handle != INVALID_HANDLE_VALUE ) {
		*pVal = (LONG)FindFileData.nFileSizeLow;
		FindClose( handle );
	}
	else {
		*pVal = 0;
	}

	return S_OK;
}
  



  ディレクトリかどうかのチェック

  
//*******************************************************************
//  ( shlwapi.lib )
//*******************************************************************
STDMETHODIMP CFile::IsDirectory(BSTR TargetPath, BOOL *pVal)
{
	USES_CONVERSION;
	LPTSTR szTargetPath = OLE2T(TargetPath);

	*pVal = PathIsDirectory( szTargetPath );

	return S_OK;
}
  










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




SQLの窓  天気  IT用語辞典
Yahoo!ニュース  マルチ辞書
PHP マニュアル  Google URL短縮 


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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ