c++获取文件(夹)属性
来源:互联网 发布:相册排版软件 编辑:程序博客网 时间:2024/04/27 19:22
HRESULT GetFolderTime( const wstring wstrPath, wstring &wstrRes)
{
if ( wstrPath.length() < 3)
{
return -1;
}
wstring wstrShortPath;
int iPos2 = wstrPath.rfind( L"//");
wstrShortPath = wstrPath.substr( 0,iPos2);
wstring wstrFileFilter;
wstring wstrFilePath = wstrPath.substr( iPos2 + 1,wstrPath.length() - iPos2);
HANDLE hFind = NULL;
WIN32_FIND_DATA fileinfo;
DOUBLE dwSize = 0;
wstrFileFilter = wstrShortPath;
wstrFileFilter += L"//*";
hFind = FindFirstFile( wstrFileFilter.c_str(), &fileinfo);
do
{
if(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//找到指定文件夹
if( fileinfo.cFileName == wstrFilePath)
{
TCHAR tchBuf[20] = { 0 };
SYSTEMTIME sysTime;
FileTimeToSystemTime( &fileinfo.ftCreationTime, &sysTime);
//创建时间
//年
_itow( sysTime.wYear, tchBuf, 10);
wstrRes += tchBuf;
//月
_itow( sysTime.wMonth, tchBuf, 10);
if( sysTime.wMonth < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
//日
_itow( sysTime.wDay, tchBuf, 10);
if( sysTime.wDay < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
wstrRes += L",";
//小时
_itow( sysTime.wHour, tchBuf, 10);
if( sysTime.wHour < 10)
{
wstrRes += L"0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//分
_itow( sysTime.wMinute, tchBuf, 10);
if( sysTime.wMinute < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//秒
_itow( sysTime.wSecond, tchBuf, 10);
if( sysTime.wSecond < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
memset( tchBuf, 0, sizeof( tchBuf));
wstrRes += L"|";
FileTimeToSystemTime( &fileinfo.ftLastWriteTime, &sysTime);
//最后修改时间
//年
_itow( sysTime.wYear, tchBuf, 10);
wstrRes += tchBuf;
//月
_itow( sysTime.wMonth, tchBuf, 10);
if( sysTime.wMonth < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
//日
_itow( sysTime.wDay, tchBuf, 10);
if( sysTime.wDay < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
wstrRes += L",";
//小时
_itow( sysTime.wHour, tchBuf, 10);
if( sysTime.wHour < 10)
{
wstrRes += L"0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//分
_itow( sysTime.wMinute, tchBuf, 10);
if( sysTime.wMinute < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//秒
_itow( sysTime.wSecond, tchBuf, 10);
if( sysTime.wSecond < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
memset( tchBuf, 0, sizeof( tchBuf));
wstrRes += L"|";
FileTimeToSystemTime( &fileinfo.ftLastAccessTime, &sysTime);
//最后访问时间
//年
_itow( sysTime.wYear, tchBuf, 10);
wstrRes += tchBuf;
//月
_itow( sysTime.wMonth, tchBuf, 10);
if( sysTime.wMonth < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
//日
_itow( sysTime.wDay, tchBuf, 10);
if( sysTime.wDay < 10)
{
wstrRes += L"-0";
wstrRes += tchBuf;
}
else
{
wstrRes += L"-";
wstrRes += tchBuf;
}
wstrRes += L",";
//小时
_itow( sysTime.wHour, tchBuf, 10);
if( sysTime.wHour < 10)
{
wstrRes += L"0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//分
_itow( sysTime.wMinute, tchBuf, 10);
if( sysTime.wMinute < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
//秒
_itow( sysTime.wSecond, tchBuf, 10);
if( sysTime.wSecond < 10)
{
wstrRes += L":0";
wstrRes += tchBuf;
}
else
{
wstrRes += L":";
wstrRes += tchBuf;
}
wstrRes += L"|";
dwSize = fileinfo.dwFileAttributes;
_ltow( dwSize, tchBuf, 10);
wstrRes += tchBuf;//文件类型
memset( tchBuf, 0, sizeof( tchBuf));
wstrRes += L"|";
}
}
}while( FindNextFile( hFind, &fileinfo));
return 0;
}
功 能 描 述: -取得目录的大小
DWORD64 GetFolderSize( const wstring wstrPath)
{
if ( wstrPath.length() < 0)
{
return -1;
}
wstring wstrFileFilter;
wstring wstrFilePath;
HANDLE hFind = NULL;
WIN32_FIND_DATA fileinfo;
DWORD64 dwSize = 0;
wstrFileFilter = wstrPath;
wstrFileFilter += L"//*";
hFind = FindFirstFile( wstrFileFilter.c_str(), &fileinfo);
do
{
if(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!wcscmp(fileinfo.cFileName,L".") || !wcscmp(fileinfo.cFileName, L".."))
{
//Do nothing for "." and ".." folders
}
else
{
wstring wstrTmp;
wstrTmp += wstrPath;
wstrTmp += L"//";
wstrTmp += fileinfo.cFileName;
dwSize = dwSize + GetFolderSize( wstrTmp);
/* if(dwFolders != NULL)
{
++(*dwFolders);
}*/
}
}
else
{
/* if(dwFiles != NULL)
{
++(*dwFiles);
}*/
}
dwSize += fileinfo.nFileSizeLow;
}while(FindNextFile(hFind,&fileinfo));
FindClose(hFind);
return dwSize;
}
功 能 描 述: -取得目录包含的子目录数目
DWORD64 GetSubFolderAmount( const wstring wstrPath)
{
if ( wstrPath.length() < 0)
{
return -1;
}
wstring wstrFileFilter;
wstring wstrFilePath;
HANDLE hFind = NULL;
WIN32_FIND_DATA fileinfo;
DWORD64 dwSize = 0;
wstrFileFilter = wstrPath;
wstrFileFilter += L"//*";
hFind = FindFirstFile( wstrFileFilter.c_str(), &fileinfo);
do
{
if( INVALID_HANDLE_VALUE != hFind && fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!wcscmp(fileinfo.cFileName,L".") || !wcscmp(fileinfo.cFileName, L".."))
{
//Do nothing for "." and ".." folders
}
else
{
wstring wstrTmp;
wstrTmp += wstrPath;
wstrTmp += L"//";
wstrTmp += fileinfo.cFileName;
GetSubFolderAmount( wstrTmp);
++ dwSize;
}
}
else
{
/* if(dwFiles != NULL)
{
++(*dwFiles);
}*/
}
}while(FindNextFile(hFind,&fileinfo));
FindClose(hFind);
return dwSize;
}
功 能 描 述: -取得目录包含的文件数目
DWORD64 GetFolderFileAmount( const wstring wstrPath)
{
if ( wstrPath.length() < 0)
{
return -1;
}
wstring wstrFileFilter;
wstring wstrFilePath;
HANDLE hFind = NULL;
WIN32_FIND_DATA fileinfo;
DWORD64 dwSize = 0;
wstrFileFilter = wstrPath;
wstrFileFilter += L"//*";
hFind = FindFirstFile( wstrFileFilter.c_str(), &fileinfo);
do
{
if( INVALID_HANDLE_VALUE != hFind && fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!wcscmp(fileinfo.cFileName,L".") || !wcscmp(fileinfo.cFileName, L".."))
{
//Do nothing for "." and ".." folders
}
else
{
wstring wstrTmp;
wstrTmp += wstrPath;
wstrTmp += L"//";
wstrTmp += fileinfo.cFileName;
dwSize += GetFolderFileAmount( wstrTmp);
}
}
else if( INVALID_HANDLE_VALUE != hFind)
{
++ dwSize;
printf( "-------%s/n", fileinfo.cFileName);
}
}while( FindNextFile(hFind,&fileinfo));
FindClose(hFind);
return dwSize;
}
- c++获取文件(夹)属性
- c/c++ 获取文件的属性
- Windows平台C语言获取文件的一些属性
- 【linux c learn 之stat】获取文件的属性
- 获取属性文件参数
- 获取属性文件properties
- 自定义获取属性文件
- 获取文件时间属性
- 获取文件基本属性
- 获取文件夹文件(C++)
- Android C 获取设备属性
- 获取图片文件的属性
- c# 获取文件的属性;
- vc++ 获取文件部分属性
- 获取属性配置config文件
- VerQueryValue获取文件-属性-详细信息
- 利用属性获取文件目录
- 获取文件的详细属性
- ViewStub Used in Android Application
- 策略→需求→建模→规划→执行
- 堆和栈
- CString 的 GetBuffer
- 历史上著名的六次经济危机
- c++获取文件(夹)属性
- 数学表达式解析-JAVA版
- 中国十大古城
- Hashtable的遍历
- 软件和需求的实践(1)
- 解决文字过长,表格被撑大,自动换行,文字超出,切割
- 驱动编写的全过程
- 未曾见过这片海
- UCML Ajax++框架介绍