21 #pragma comment(lib,"SHLWAPI.lib")
36 #define FOF_NOERRORUI 0x0400
86 CFileName(LPCTSTR lpszName,
bool dummy) : m_boIsExists(false)
102 bool r = !! ::PathSearchAndQualify(lpszName, s1.
GetBuffer(MAX_PATH), MAX_PATH);
106 r = (::GetLongPathName(s1, s2.
GetBuffer(MAX_PATH), MAX_PATH) != 0);
116 m_strName = lpszName;
129 void Set(LPCTSTR lpszName,
const WIN32_FILE_ATTRIBUTE_DATA& tFileAttr)
131 m_strName = lpszName;
143 void Set(LPCTSTR lpszPath,
const WIN32_FIND_DATA& t)
145 m_strName.
Format(_T(
"%s\\%s"), lpszPath, t.cFileName);
146 m_strName.
Replace(_T(
"\\\\"), _T(
"\\"));
148 m_tInfo.dwFileAttributes = t.dwFileAttributes;
149 m_tInfo.ftCreationTime = t.ftCreationTime;
150 m_tInfo.ftLastAccessTime = t.ftLastAccessTime;
151 m_tInfo.ftLastWriteTime = t.ftLastWriteTime;
152 m_tInfo.nFileSizeHigh = t.nFileSizeHigh;
153 m_tInfo.nFileSizeLow = t.nFileSizeLow;
175 operator LPCTSTR(
void)
const
197 ::GetShortPathName(m_strName, str.
GetBuffer(MAX_PATH), MAX_PATH);
214 return m_strName.
Mid(p + 1);
227 INDEX idx = s.
Find(_T(
'.'));
228 if ( idx != INVALID_INDEX )
258 if ( p >= 0 && p1 < p )
260 return m_strName.
Mid(p + 1);
274 return m_strName.
Left(p);
291 i.HighPart = m_tInfo.nFileSizeHigh;
292 i.LowPart = m_tInfo.nFileSizeLow;
308 ::SetLastError(NO_ERROR);
310 WIN32_FILE_ATTRIBUTE_DATA t;
311 if ( ::GetFileAttributesEx(fn, GetFileExInfoStandard, &t) )
314 if ( (t.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 )
317 l.HighPart = t.nFileSizeHigh;
318 l.LowPart = t.nFileSizeLow;
325 l.LowPart = ::GetCompressedFileSize(fn, &h);
326 if ( ::GetLastError() == 0 )
331 DWORD sectorsPerCluster;
332 DWORD bytesPerSector;
333 DWORD numberOfFreeClusters;
334 DWORD totalNumberOfClusters;
335 if ( ::GetDiskFreeSpace(
GetPathName(), §orsPerCluster, &bytesPerSector, &numberOfFreeClusters, &totalNumberOfClusters) )
337 DWORD d = sectorsPerCluster * bytesPerSector;
338 r = (r + d - 1) / d * d;
366 DWORD sectorsPerCluster;
367 DWORD bytesPerSector;
368 DWORD numberOfFreeClusters;
369 DWORD totalNumberOfClusters;
370 if ( ::GetDiskFreeSpace(
GetPathName(), §orsPerCluster, &bytesPerSector, &numberOfFreeClusters, &totalNumberOfClusters) )
372 return sectorsPerCluster * bytesPerSector;
389 if ( r && P != NULL )
406 if ( r && P != NULL )
409 P->dwFileAttributes = m_tInfo.dwFileAttributes;
410 P->ftCreationTime = m_tInfo.ftCreationTime;
411 P->ftLastAccessTime = m_tInfo.ftLastAccessTime;
412 P->ftLastWriteTime = m_tInfo.ftLastWriteTime;
413 P->nFileSizeHigh = m_tInfo.nFileSizeHigh;
414 P->nFileSizeLow = m_tInfo.nFileSizeLow;
415 #if !defined(_WIN32_WCE)
435 if ( p >= 0 && p1 < p )
437 if ( lpszExt != NULL )
439 return s.
Left(p) + lpsz + _T(
".") + lpszExt;
441 return s.
Left(p) + lpsz + s.
Mid(p);
443 if ( lpszExt != NULL )
445 return s + lpsz + _T(
".") + lpszExt;
457 m_boIsExists = ms_GetInfo(m_strName, &m_tInfo);
466 bool IsReadOnly(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_READONLY); }
473 bool IsDirectory(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_DIRECTORY); }
480 bool IsCompressed(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_COMPRESSED); }
487 bool IsSystem(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_SYSTEM); }
494 bool IsHidden(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_HIDDEN); }
501 bool IsTemporary(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_TEMPORARY); }
508 bool IsNormal(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_NORMAL); }
515 bool IsArchived(
void)
const {
return m_IsAttr(FILE_ATTRIBUTE_ARCHIVE); }
524 if ( m_boIsExists ){ ft = m_tInfo.ftLastWriteTime; }
535 if ( m_boIsExists ){ ft = m_tInfo.ftLastAccessTime; }
546 if ( m_boIsExists ){ ft = m_tInfo.ftCreationTime; }
555 bool SetReadOnly(
void){
return m_SetAttr(FILE_ATTRIBUTE_READONLY); }
562 bool SetHidden(
void){
return m_SetAttr(FILE_ATTRIBUTE_HIDDEN); }
569 bool SetNormal(
void){
return m_SetAttr(FILE_ATTRIBUTE_NORMAL); }
582 if ( file.
Open(m_strName) )
585 file.
SetTime(timeCreation, timeLastAccess, timeLastWrite);
587 return ::GetLastError();
602 HANDLE h = ::FindFirstFile(m_strName + lpszOpt, &t);
603 if ( h != INVALID_HANDLE_VALUE )
607 if ( t.cFileName[0] !=
'.' )
609 vstrResult.
Add(
CStr::Fmt(_T(
"%s\\%s"), m_strName, t.cFileName));
611 if ( ! ::FindNextFile(h, &t) )
630 if ( ! ::CreateDirectory(m_strName, NULL) )
632 DWORD e = ::GetLastError();
633 if ( e == ERROR_NOT_READY )
637 if ( e != ERROR_ALREADY_EXISTS )
640 if ( m_strName == n )
645 if ( ! ::CreateDirectory(m_strName, NULL) )
667 bool Rename(LPCTSTR lpszNew,
bool boIsAllowUndo =
false,
bool boIsSilent =
true)
672 if ( m_ShFileOp(FO_RENAME, fnNew, boIsAllowUndo, boIsSilent) )
692 bool Remove(
bool boIsAllowUndo =
false,
bool boIsSilent =
true)
694 if (
IsExist() && m_ShFileOp(FO_DELETE, NULL, boIsAllowUndo, boIsSilent) )
714 bool CopyTo(LPCTSTR lpszNew,
bool boIsAllowUndo =
false,
bool boIsSilent =
true)
716 if (
IsExist() && m_ShFileOp(FO_COPY, m_FullPath(lpszNew), boIsAllowUndo, boIsSilent) )
735 bool MoveTo(LPCTSTR lpszNew,
bool boIsAllowUndo =
false,
bool boIsSilent =
true)
740 if ( m_ShFileOp(FO_MOVE, fnNew, boIsAllowUndo, boIsSilent) )
770 if ( f1 >= 0 && f2 < f1 )
777 s.
Format(_T(
"%s(%d)%s"), p1, i + 1, p2);
780 if (
CopyTo(s, boIsAllowUndo,
true) )
790 if (
CopyTo(s, boIsAllowUndo,
true) )
809 bool MakeShortcut(LPCTSTR lpszLinkName, LPCTSTR lpszDescription, LPCTSTR lpszParameter = NULL)
const
813 IShellLink* pSL = NULL;
814 HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
815 IID_IShellLink,
reinterpret_cast<LPVOID*
>(&pSL));
818 pSL->SetPath(m_strName);
820 pSL->SetDescription(lpszDescription);
821 if ( lpszParameter != NULL )
823 pSL->SetArguments(lpszParameter);
826 IPersistFile* pPF = NULL;
827 hr = pSL->QueryInterface(IID_IPersistFile,
reinterpret_cast<LPVOID*
>(&pPF));
830 hr = pPF->Save(
CUnicode(lpszLinkName), TRUE);
837 return SUCCEEDED(hr);
839 CStr ln = lpszLinkName;
854 IShellLink* pSL = NULL;
855 HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
856 IID_IShellLink,
reinterpret_cast<LPVOID*
>(&pSL));
859 IPersistFile* pPF = NULL;
860 hr = pSL->QueryInterface(IID_IPersistFile,
reinterpret_cast<LPVOID*
>(&pPF));
863 hr = pPF->Load(
CUnicode(m_strName), STGM_READ);
870 return SUCCEEDED(hr);
873 if ( ::SHGetShortcutTarget(m_strName, s.
GetBuffer(MAX_PATH), MAX_PATH) )
894 IShellLink* pSL = NULL;
895 HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
896 IID_IShellLink,
reinterpret_cast<LPVOID*
>(&pSL));
899 IPersistFile* pPF = NULL;
900 hr = pSL->QueryInterface(IID_IPersistFile,
reinterpret_cast<LPVOID*
>(&pPF));
903 hr = pPF->Load(
CUnicode(m_strName), STGM_READ);
904 if ( hWnd != NULL && SUCCEEDED(hr) )
906 hr = pSL->Resolve(hWnd, 0);
912 hr = pSL->GetPath(path.
GetBuffer(MAX_PATH), MAX_PATH, &wfd, SLGP_SHORTPATH);
918 hr = pSL->GetDescription(_description.
GetBuffer(MAX_PATH), MAX_PATH);
931 return SUCCEEDED(hr);
934 if ( ::SHGetShortcutTarget(m_strName, s.
GetBuffer(MAX_PATH), MAX_PATH) )
938 _description.
Empty();
971 bool m_IsAttr(DWORD dwCheck)
const
975 return (m_tInfo.dwFileAttributes & dwCheck) != 0;
980 bool m_SetAttr(DWORD dwAttr)
982 bool r = !! ::SetFileAttributes(m_strName, dwAttr);
983 m_boIsExists = ms_GetInfo(m_strName, &m_tInfo);
987 static bool ms_GetInfo(LPCTSTR lpszName, LPWIN32_FILE_ATTRIBUTE_DATA P)
990 HANDLE h = ::FindFirstFile(lpszName, &t);
991 if ( h != INVALID_HANDLE_VALUE )
994 P->dwFileAttributes = t.dwFileAttributes;
995 P->ftCreationTime = t.ftCreationTime;
996 P->ftLastAccessTime = t.ftLastAccessTime;
997 P->ftLastWriteTime = t.ftLastWriteTime;
998 P->nFileSizeHigh = t.nFileSizeHigh;
999 P->nFileSizeLow = t.nFileSizeLow;
1009 CStr m_FullPath(LPCTSTR lpszName)
1013 if ( ::PathIsRelative(lpszName) )
1035 bool m_ShFileOp(WORD wFunc, LPCTSTR lpszTo,
bool boIsAllowUndo,
bool boIsSilent)
1038 return m_ShFileOp(wFunc, strdntFrom, lpszTo, boIsAllowUndo, boIsSilent);
1051 bool boIsAllowUndo,
bool boIsSilent)
1053 SHFILEOPSTRUCT tFileOp;
1055 tFileOp.hwnd = NULL;
1056 tFileOp.wFunc = wFunc;
1057 tFileOp.pFrom = strdntFrom;
1059 if ( lpszTo != NULL )
1061 tFileOp.pTo = strdntTo;
1066 tFileOp.fFlags |= FOF_SILENT
1067 | FOF_NOCONFIRMATION
1070 if ( boIsAllowUndo )
1072 tFileOp.fFlags |= FOF_ALLOWUNDO;
1074 tFileOp.fAnyOperationsAborted = FALSE;
1075 tFileOp.hNameMappings = NULL;
1076 tFileOp.lpszProgressTitle = _T(
"");
1077 return ::SHFileOperation(&tFileOp) == 0;
1080 mutable bool m_boIsExists;
1081 mutable WIN32_FILE_ATTRIBUTE_DATA m_tInfo;
#define loop(VAR, CNT)
loop構文.
Double Null Terminate(DNT)型文字列操作関係のヘッダ
Double Null Terminate(DNT)型文字列管理
CStr GetExtName(void) const
[取得] 拡張子取得
CFileTimeEx GetCreationTime(void) const
[取得] 作成日時取得
bool CopyTo(LPCTSTR lpszNew, bool boIsAllowUndo=false, bool boIsSilent=true)
[操作] コピー.
static bool IsExist(LPCTSTR lpszPath)
[確認] 有無チェック.
bool ResolveShortcut(void)
[設定] ショートカット解決.
bool SetNormal(void)
[設定] Normal属性設定
bool IsDirectory(void) const
[確認] Directory属性チェック
bool IsExist(void) const
[確認] 有無チェック
CStr GetPathName(void) const
[取得] パス取得
CFileTimeEx GetLastAccessTime(void) const
[取得] 最終アクセス日時取得
bool IsReadOnly(void) const
[確認] ReadOnly属性チェック
void Set(LPCTSTR lpszPath, const WIN32_FIND_DATA &t)
[設定] 代入
CStr CopyEx(LPCTSTR lpszNew, bool boIsAllowUndo=false)
[操作] コピー.
bool IsShortcut(void) const
[確認] Shortcutチェック
bool MoveTo(LPCTSTR lpszNew, bool boIsAllowUndo=false, bool boIsSilent=true)
[操作] ムーブ.
bool IsArchived(void) const
[確認] Archived属性チェック
bool IsCompressed(void) const
[確認] Compressed属性チェック
CStr GetFullName(void) const
[取得] フルName名取得
bool SetReadOnly(void)
[設定] ReadOnly属性設定
bool MakeShortcut(LPCTSTR lpszLinkName, LPCTSTR lpszDescription, LPCTSTR lpszParameter=NULL) const
[作成] ショートカット作成.
CStr GetFileTitle(void) const
[取得] ファイルタイトル取得
bool IsHidden(void) const
[確認] Hidden属性チェック
CFileName(LPCTSTR lpszName, bool dummy)
代入コンストラクタ.
DWORD GetBytesOfCluster(void) const
[取得] クラスタサイズ取得.
CStr GetFullShortName(void) const
[取得] FullShortName名取得
bool IsTemporary(void) const
[確認] Temporary属性チェック
CStr InsertAtEndOfName(LPCTSTR lpsz, LPCTSTR lpszExt=NULL) const
[取得] ファイル名末文字列追加.
CStr GetShortName(void) const
[取得] ShortName名取得
bool MakeDirectory(void)
[作成] フォルダ作成.
bool Rename(LPCTSTR lpszNew, bool boIsAllowUndo=false, bool boIsSilent=true)
[操作] リネーム.
CStr GetFileName(void) const
[取得] ファイル名取得
void Set(LPCTSTR lpszName, const WIN32_FILE_ATTRIBUTE_DATA &tFileAttr)
[設定] 代入
CFileName(LPCTSTR lpszName)
代入コンストラクタ
LONGLONG GetSize(void) const
[取得] ファイルサイズ取得
bool SetHidden(void)
[設定] Hidden属性設定
DWORD SetTime(const CFileTimeEx &timeCreation, const CFileTimeEx &timeLastAccess, const CFileTimeEx &timeLastWrite)
[設定] ファイル日付設定
bool IsSystem(void) const
[確認] System属性チェック
CStrVector GetFiles(LPCTSTR lpszOpt=_T("\\*.*"))
[作成] ファイル一覧作成
bool GetFindData(LPWIN32_FIND_DATA P) const
[取得] ファイル情報取得
LONGLONG GetSizeOnDisk(void) const
[取得] ディスク上のサイズ取得
CFileTimeEx GetLastWriteTime(void) const
[取得] 最終書込み日時取得
bool Remove(bool boIsAllowUndo=false, bool boIsSilent=true)
[操作] 削除.
bool IsSameFile(LPCTSTR lpszName) const
[確認] 比較.
CFileName & operator=(LPCTSTR lpszName)
[設定] 代入オペレーション
bool GetAttributeData(LPWIN32_FILE_ATTRIBUTE_DATA P) const
[取得] ファイル情報取得
bool IsNormal(void) const
[確認] Normal属性チェック
bool ResolveShortcut(CStr &_description, HWND hWnd=NULL)
[設定] ショートカット解決.
bool Open(LPCTSTR lpszName, bool boIsShare=true, bool boIsBottom=true)
[操作] オープン.
void SetTime(const CFileTimeEx &timeCreation, const CFileTimeEx &timeLastAccess, const CFileTimeEx &timeLastWrite)
[設定] ファイル日付設定
INT_PTR ReverseFind(TYP t) const
[確認] 検索(後ろから)
INT_PTR ReverseFindOneOf(const TYP *lpsz) const
[確認] 検索(後ろから)
CStrT Left(size_t iSize) const
[作成] 範囲取得.
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
INT_PTR Find(TYP t, INDEX iFromIndex=0) const
[確認] 検索.
CStrT & TrimRight(TYP t=' ')
[処理] 末尾から文字をトリム.
int Replace(TYP tOld, TYP tNew)
[処理] 文字置換.
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
int CompareNoCase(const TYP *lpszSubject) const
[確認] 文字列比較(大小区別無く比較)
CStrT Mid(INDEX iOffset, size_t iSize=INVALID_SIZE) const
[作成] 範囲取得.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
TNB::CStrT< WCHAR > CUnicode
UNICODE文字列クラス
void Copy(LPSTR _dst, LPCSTR src)
[複製] 文字列コピー(ASCII/SJIS用)
CStr GetProcessPath(void)
[取得] プロセスのパス取得.