コード例 #1
0
ファイル: LogMgr.cpp プロジェクト: azureidea/DuiVision
// 遍历文件以及子文件夹,这里不处理子文件夹
bool CLogMgr::BrowseDir(const TCHAR *dir,const TCHAR *filespec)
{
	// 遍历文件
	CFileFind logFind;
	CString strDir = dir;
	strDir.Format(_T("%s\\%s"), dir, filespec);

	try
	{
		// 查找第一个文件
		BOOL IsFinded=(BOOL)logFind.FindFile(strDir); 
		while(IsFinded) 
		{  
			IsFinded=(BOOL)logFind.FindNextFile();
			if(!logFind.IsDots()) 
			{ 
				TCHAR foundFileName[_MAX_FILE_PATH]; 
				memset(foundFileName, 0, _MAX_FILE_PATH);

				CString strFileName = logFind.GetFileName();
				T_STRNCPY(foundFileName, strFileName.GetBuffer(_MAX_FILE_PATH), (_MAX_FILE_PATH - 1));
				strFileName.ReleaseBuffer();

				if(logFind.IsDirectory()) // 如果是目录不处理
				{ 
					continue;
				} 
				else // 查找到文件
				{ 
					TCHAR filename[_MAX_FILE_PATH];
					memset(filename, 0x00, _MAX_FILE_PATH*sizeof(TCHAR));
					T_STRCPY(filename,dir);
					T_STRCAT(filename,foundFileName);

					CTime lastWriteTime;
					logFind.GetLastWriteTime(lastWriteTime);
					if (!ProcessFile(filename, (time_t)lastWriteTime.GetTime()))
						return false;
				} 
			} 
		} 
		logFind.Close(); 
	}
	catch (...)
	{
		return false;
	}

	return true;
}
コード例 #2
0
/**
 * get the modification date of the file
 *
 * @param fileName		the file name
 * @param timeStamp		the timestamp
 * @return				TRUE if file exists,
 *						else FALSE 
 * @exception  
 * @see        
 */
BOOL CEFile::GetTimeStamp(LPCTSTR fileName, time_t* pTimeStamp)
{
	CFileFind finder;
	BOOL bWorking = finder.FindFile(fileName);
	if (bWorking)
	{
		CTime refTime;
		bWorking = finder.FindNextFile();
		finder.GetLastWriteTime( refTime ) ;
		*pTimeStamp = refTime.GetTime();
		return TRUE;
	}
	else
		return FALSE;
}
コード例 #3
0
ファイル: Misc.cpp プロジェクト: CyberShadow/Ditto
__int64 GetLastWriteTime(const CString &csFile)
{
	__int64 nLastWrite = 0;
	CFileFind finder;
	BOOL bResult = finder.FindFile(csFile);

	if (bResult)
	{
		finder.FindNextFile();

		FILETIME ft;
		finder.GetLastWriteTime(&ft);

		memcpy(&nLastWrite, &ft, sizeof(ft));
	}

	return nLastWrite;
}
コード例 #4
0
//==============================================================================
bool CDiskItem::getInfo()
{
	CFileFind finder;
	BOOL bFound = finder.FindFile( getFullName() );
		// TO DO: Only one file must be found!
	if( bFound )
	{
		/*bNext=*/ finder.FindNextFile();

	// (2) Get exact file name from the disk to exclude differences
	//	   in capitalization
		CDiskItem tmpDiskItem( finder.GetFilePath() );

		CString strRoot = tmpDiskItem.getFullPath();
			/* (3) Was, but was wrong with UNC:
				CString strRoot = finder.GetRoot(); */
		CDiskItem roottt( strRoot );

		if( ! roottt.m_strName.IsEmpty() )
		{
			roottt.getInfo();	// Recursively
			this->m_strDir = AddWithSlash( roottt.m_strDir, roottt.m_strName ) + L"\\";
		}
		this->m_strName = tmpDiskItem.m_strName;
	// End of (2)

		FILETIME ft;
// TO DO: Error processing?
		/*if(!  ??? */ finder.GetLastWriteTime( &ft );
		m_LastWriteTime = ft;

    m_size = finder.GetLength();
		if( finder.IsDirectory() )
			m_nType = DI_FOLDER;
		else
			m_nType = DI_FILE;
	}
	finder.Close();
	return (bFound != 0);
}
コード例 #5
0
ファイル: CReplayFrame.cpp プロジェクト: seawei/openholdem
CReplayFrame::CReplayFrame(void)
{
	__SEH_SET_EXCEPTION_HANDLER

    CTime		time = 0, latest_time = 0;
    int			last_frame_num = -1, frame_num = 0;
    CString		path = "", filename = "", current_path = "";
    CFileFind	hFile;
    BOOL		bFound = false;

	CSLock lock(m_critsec);

	// Find next replay frame number
    _next_replay_frame = -1;

    path.Format("%s\\replay\\session_%lu\\*.bmp", _startup_path, theApp._session_id);
    bFound = hFile.FindFile(path.GetString());
    while (bFound)
    {
        bFound = hFile.FindNextFile();
        if (!hFile.IsDots() && !hFile.IsDirectory())
        {
            filename = hFile.GetFileName();
            hFile.GetLastWriteTime(time);
            sscanf_s(filename.GetString(), "frame%d.bmp", &frame_num);

            if (time>latest_time)
            {
                last_frame_num = frame_num;
                latest_time = time;
            }
        }
    }

    _next_replay_frame = last_frame_num + 1;
    if (_next_replay_frame >= prefs.replay_max_frames())
        _next_replay_frame = 0;
}
コード例 #6
0
ファイル: SingelControl.cpp プロジェクト: chenzhengxi/chaser
void CSingelControl::OnButtonResult() 
{
    // TODO: Add your control notification handler code here
    CStdioFile f;
    if(m_strResultFile.GetLength()<=1)
        return;
    int i;
    CFileFind Find;
    CTime TimeOld;
    m_nIndex=-1;
    CTime TimeNew;
    for(i=0;i<5;i++)
    {
        CString str=m_strPath+m_strResultFileExt[i];
        if(Find.FindFile(str))
        {
            Find.FindNextFile();
            Find.GetLastWriteTime(TimeNew);
            if(TimeNew>TimeOld)
            {
                TimeOld=TimeNew;
                m_nIndex=i;
            }
        };
    }
    if(m_nIndex>=0&&m_nIndex!=4)
    {
        m_strResultFile=m_strResultFileExt[m_nIndex];
    }
    UpdateData(false);
    f.Open(m_strPath+m_strResultFile,CFile::modeRead);
    if(f.m_hFile!=NULL)
    {
        m_bResult=true;
        CTxtdlg dlg(&f);
        dlg.DoModal();
        f.Close();
        if(m_nIndex>=0&&m_nIndex!=4)
        {
            AfxMessageBox("测试结果不合格");
        }
        else
        {
            CFile f2;
            f2.Open(m_strPath+m_strResultFile,CFile::modeRead);	
            m_TxtResult.nInfolth=f2.GetLength();
            if(m_TxtResult.strInfo)
                delete[] m_TxtResult.strInfo;
            m_TxtResult.strInfo  =new INT8[m_TxtResult.nInfolth];
            f2.Read(m_TxtResult.strInfo,m_TxtResult.nInfolth);
            f2.Close();
            m_TxtResult.nStepCode=m_pControl->nStep;
            m_TxtResult.nAparatusInnerSeriaNumber=m_Product.nInnerSeriaNumber;
            int nSeriaNumber;
            m_pDatalib->GetSeriaNumber(&nSeriaNumber);
            m_TxtResult.nID=nSeriaNumber;

            m_ControlResult.nTxtID=m_TxtResult.nID;
            m_ControlResult.nResult=(m_nIndex==4);
            memcpy(m_TxtResult.strName,m_pControl->strItemName,sizeof(char)*_MAX_DESCRIPTION_CNT);
            m_BTStart.EnableWindow(false);
            m_BTResult.EnableWindow(true);
            m_BTSave.EnableWindow(true);
            m_BTResultName.EnableWindow(true);
            m_BTNext.EnableWindow(false);
            m_BTInput.EnableWindow(false);
            m_BTNext.EnableWindow(true);
            m_STQueryCode.ShowWindow(m_pControl->nStep==m_Product.Aparatus.nControlcnt-1);
            m_ETQueryCode.ShowWindow(m_pControl->nStep==m_Product.Aparatus.nControlcnt-1);
        }
    }else
    {
        m_bResult=false;
        AfxMessageBox("控制结果文件不存在");
    }
}
コード例 #7
0
ファイル: OpenFileDlg.cpp プロジェクト: IMSoP/CDex
void COpenFileDlg::AddRecursiveFiles( const CUString& strDir,int nItem )
{
	CFileFind	fileFind;
	CUString		pathAndFileType = strDir + CUString( _W( "\\*.*" ));
	BOOL		bStop=FALSE;

    CUStringConvert strCnv;

	// Iterate through the items in the listbox and populate the listconrol.
	if (fileFind.FindFile( strCnv.ToT( pathAndFileType ) ) )
	{
		do
		{
			bStop=(fileFind.FindNextFile()==0);
			CUString strFileName = CUString( fileFind.GetFileName() );
			CUString strFileRoot = CUString( fileFind.GetRoot() );
			CUString strFileType;

			if (	TRUE == fileFind.IsDirectory() && 
					FALSE == fileFind.IsDots() &&
					TRUE == m_bRecursiveDir )
			{
				AddRecursiveFiles( strDir + CUString( _W( "\\" ) ) + strFileName, nItem );
			}

			if (fileFind.IsDirectory()==FALSE && fileFind.IsDots()==FALSE)
			{
				int nPos=strFileName.ReverseFind( _T( '.' ) );
				

				if (nPos>0)
				{
					CUString strExt;
					strExt = strFileName.Right(strFileName.GetLength()-nPos-1);

					strFileType = strExt;

					strExt.MakeUpper();

					if ( CompareExt( strExt ) == TRUE )
					{
						CUString strFileSize;
						CUString strFileDate;
						CTime	fileTime;

						// Get the data/time stamp of this file
						fileFind.GetLastWriteTime( fileTime );

						// Format date time string
						strFileDate.Format( _W( "%4d/%02d/%02d %02d:%02d" ), fileTime.GetYear(), fileTime.GetMonth(), fileTime.GetDay(), fileTime.GetHour(), fileTime.GetMinute() );

						strFileSize.Format( _W( "%10.2f" ), fileFind.GetLength() / ( 1024.0 * 1024.0 ) );

                        CUStringConvert strCnv;

						m_ctrlRequestedFiles.InsertItem( nItem, strCnv.ToT( strFileName ));

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_TYPE, strCnv.ToT( strFileType ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_DATE ,strCnv.ToT( strFileDate ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_PATH, strCnv.ToT( strFileRoot ) );

						m_ctrlRequestedFiles.SetItemText( nItem, FILE_OPEN_SIZE, strCnv.ToT( strFileSize ) );

						m_ctrlRequestedFiles.SetItemData( nItem, (DWORD)fileTime.GetTime() );

						nItem++;
					}
				}
			}
		} while (bStop!=TRUE);
	}	


	m_bSortAscending=TRUE;
}
コード例 #8
0
//------------------------------------------------
// 파일의 리스트 및 각 파일에 대한 자세한 정보를 
// 함께 저장하게 됨
// data.h파일에 해당 구조체를 선언한다.
//--------------------------------------------------
void CMyExplorerDoc::SelectTreeViewFolder(CString strFullName)
{

	LIST_VIEW*	pListView;
	CFileFind	ff;

	// 사용자가 폴더를 선택할 때마다 파일 리스트를
	// 새로 업데이트 해야 함
	// 따라서 기존 정보를 모두 삭제한다.
	if (m_pFileList != NULL)
		RemoveAllFileList();

	m_pFileList = new CObList;

	SetCurrentPath(strFullName);
	strFullName += "*.*";

	if (ff.FindFile(strFullName) == TRUE)
	{
		BOOL	bFlag = TRUE;
		while(bFlag == TRUE)
		{
			bFlag = ff.FindNextFile();

			// 디렉토리 , 도트파일이면 다시 찾음 
			if (ff.IsDirectory() || ff.IsDots())
				continue;
			
			// 파일 정보를 알아내서LIST_VIEW 구조체에 
			// 저장한 후 
			// 그것을 모두 m_pFileList에 저장한다.
			pListView = new LIST_VIEW;
			InitListViewStruct(pListView);

			pListView->strName = ff.GetFileName();
			pListView->strPath = ff.GetFilePath();

			CString		strName = pListView->strName;
			CString		strExt = ff.GetFileTitle();

			int			nNum = strName.GetLength() - strExt.GetLength();

			if (nNum == 0)
				strExt = "";
			else
				strExt = strName.Right(nNum - 1);
			pListView->strKind = strExt + " 파일";
			pListView->dwFileSize = ff.GetLength();

			CTime	time;
			if (ff.GetCreationTime(time) == TRUE)
				pListView->tCreateTime = time;
			if (ff.GetLastAccessTime(time) == TRUE)
				pListView->tLastAccessTime = time;
			if (ff.GetLastWriteTime(time) == TRUE)
				pListView->tLastWriteTime = time;
			if (ff.IsHidden() == TRUE)
				pListView->bIsHidden = TRUE;
			if (ff.IsReadOnly() == TRUE)
				pListView->bIsReadOnly = TRUE;
			if (ff.IsArchived() == TRUE)
				pListView->bIsArchived = TRUE;
			if (ff.IsSystem() == TRUE)
				pListView->bIsSystem = TRUE;

			m_pFileList->AddTail((CObject*)pListView);
		}
	}
	ff.Close();

	//------------------------------
	m_pExpListView->SetFileList();
	//-------------------------------------
}
コード例 #9
0
//----------------------------------------------------------------------------
int CSTATImageVerify::EnableVerification(int fudge)
{
	// temp variable
	FILETIME creationtime;
	creationtime.dwLowDateTime = 0;
	creationtime.dwHighDateTime = 0;

	// initialise settings
	iImageCount = 0;
	lastrefimageloaded = 0;
	margin = fudge;

	// check limits
	if (margin < 0)
		margin = 0;
	if (margin > 100)
		margin = 100;

	// populate our array with images
	CFileFind refimagefinder;
	if (refimagefinder.FindFile(referenceimagedir + _T("\\*.bmp"), 0))
	{
		int i = 0;
		int iMoreFiles = true;
		for (i=0;i<VERIFY_MAX_IMAGES;i++)
		{
			if (iMoreFiles)
			{
				iMoreFiles = refimagefinder.FindNextFile();
  				refimagearray[i].completefilenamepath = refimagefinder.GetFilePath();	//store filename into array string variable
				refimagefinder.GetLastWriteTime(&creationtime);		//store corresponding modification time
				refimagearray[i].lCreationTime = (((ULONGLONG) creationtime.dwHighDateTime) << 32) + creationtime.dwLowDateTime;
				iImageCount++;
			}
			else
			{
				refimagearray[i].completefilenamepath = _T("");
				refimagearray[i].lCreationTime = 0;
			}
		}

		refimagefinder.Close();
	}
	
	// now sort into date/time order
	if (iImageCount)
	{
		CSTATReferenceImages temp;
		bool bNotFinished = true;
		int i = 0;
		while (bNotFinished)
		{
			bNotFinished = false;
			for (i=0;i<iImageCount;i++)
			{
				if ((i + 1) < iImageCount &&
					refimagearray[i+1].lCreationTime < refimagearray[i].lCreationTime)
				{
					temp = refimagearray[i];
					refimagearray[i]= refimagearray[i+1];
					refimagearray[i+1]= temp;
					bNotFinished = true;
				}
			}
		}
	}

	return iImageCount;
}
コード例 #10
0
ファイル: CpDialog.cpp プロジェクト: jimmccurdy/ArchiveGit
DWORD CCpDialog::UpdateFolder(LPCSTR strSrcFolder, LPCSTR strDstFolder, bool bIncludeSubFolders)
{
	CString strSrcPath = strSrcFolder + CString("*.*");

	DWORD dwFileCount = 0;
	CFileFind FileFind;
	BOOL bFound = FileFind.FindFile(strSrcPath);
	while (bFound)
	{
		bFound = FileFind.FindNextFile();
		if (FileFind.IsDots())
			continue;

		CString strSrcFilePath = FileFind.GetFilePath();
		CString strSrcFileName = FileFind.GetFileName();

		if (FileFind.IsDirectory())
		{
			if (!bIncludeSubFolders)
				continue;

			CString strNewDstFolder = CString(strDstFolder) + strSrcFileName + "\\";
			bool bCreated = !!::CreateDirectory(strNewDstFolder, NULL);
			if (bCreated)
				dwFileCount++;

			CString strNewSrcFolder = strSrcFilePath + "\\";
			dwFileCount += UpdateFolder(strNewSrcFolder, strNewDstFolder);
			continue;
		}

		FILETIME SrcCreationTime;
		FILETIME SrcAccessedTime;
		FILETIME SrcModfiedTime;
		FileFind.GetCreationTime(&SrcCreationTime);
		FileFind.GetLastAccessTime(&SrcAccessedTime);
		FileFind.GetLastWriteTime(&SrcModfiedTime);

		CString strDstFilePath = CString(strDstFolder) + strSrcFileName;
		if (FileExists(strDstFilePath))
		{
			FILETIME DstCreationTime;
			FILETIME DstAccessedTime;
			FILETIME DstModfiedTime;
			bool bOK = GetFileTimes(strDstFilePath, DstCreationTime, DstAccessedTime, DstModfiedTime);
			if (CFileTime(SrcModfiedTime) <= CFileTime(DstModfiedTime))
				continue;

			DWORD dwFileAttributes = ::GetFileAttributes(strDstFilePath);
			if (dwFileAttributes && FILE_ATTRIBUTE_READONLY)
				::SetFileAttributes(strDstFilePath, dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
		}

		bool bCopied = !!::CopyFile(strSrcFilePath, strDstFilePath, false/*bFailIfExists*/);
		if (bCopied)
		{
			dwFileCount++;
			SetFileTimes(strDstFilePath, SrcCreationTime, SrcAccessedTime, SrcModfiedTime);
		}
	}
	
	FileFind.Close();
	return dwFileCount;
}
コード例 #11
0
ファイル: SearchModule.cpp プロジェクト: ccpwcn/QuickSearch
// 在指定的磁盘查找符合要求的数据,使用递归查找,支持通配符
void RecursiveTraverseFind(__in LPSEARCH_PROGRRESS_INFO lpProgressInfo)
{
	CFileFind fileFinder;
	CString strFilePath, strFileNotMatchPath;
	static short nFirstCall = 0;

	strFileNotMatchPath = lpProgressInfo->m_szStartLocation;
	nFirstCall = 1;
	/*if (lpProgressInfo->m_szStartLocation[_tcslen(lpProgressInfo->m_szStartLocation) - 1] == _T('\\'))
	{
		strFileNotMatchPath.Delete(strFileNotMatchPath.GetLength() - 1);
		strFilePath.Format(_T("%s*.*"), lpProgressInfo->m_szStartLocation);
	}
	else*/
	{
		strFilePath.Format(_T("%s\\*.*"), lpProgressInfo->m_szStartLocation);
	}

	// 如果收到了中断信号,立即返回
	if (g_hBrokenEvent && WaitForSingleObject(g_hBrokenEvent, 5) == WAIT_OBJECT_0)
		return;

	// 先按所有文件查找,看有没有文件,如果有,再往下走,如果没有,直接返回
	BOOL bWorking = fileFinder.FindFile(strFilePath);
	TCHAR szMsg[nMSG_SIZE] = { 0 };
	while (bWorking)
	{
		bWorking = fileFinder.FindNextFile();

		if (fileFinder.IsDots())
			continue;

		lpProgressInfo->m_nViewCount++;

		// 不管是目录还是文件,先按指定规则进行匹配
		CString strCurrentFile, strCurrentPath;
		strCurrentFile = fileFinder.GetFileName();
		strCurrentPath = fileFinder.GetFilePath();
		for (std::vector<STRING>::iterator it = lpProgressInfo->m_vecSearchStrings.begin(); it != lpProgressInfo->m_vecSearchStrings.end(); it++)
		{
			if (_StrStrI(strCurrentFile, it->c_str()))
			{
				FIND_DATA fd = { 0 };
				StringCchCopy(fd.m_szFilename, MAX_PATH - 1, strCurrentFile);
				StringCchCopy(fd.m_szLocation, MAX_PATH - 1, strCurrentPath);
				FILETIME ft = { 0 };
				if (fileFinder.GetLastWriteTime(&ft))
				{
					FileTimeToSystemTime(&ft, &fd.m_stFileDateAndTime);
				}
				fd.m_dwFileSize = GetUserFileSize(strCurrentPath);
				g_clsMutex.Lock();
				g_vecCurrentFindData.push_back(fd);
				lpProgressInfo->m_nFoundCount++;
				StringCchPrintf(
					szMsg,
					nMSG_SIZE - 1,
					_T("正在搜索[%d/%d]%s"),
					lpProgressInfo->m_nFoundCount,
					lpProgressInfo->m_nViewCount,
					strCurrentPath);
				lpProgressInfo->m_Update(lpProgressInfo->m_lpDlg, &fd, szMsg);
				g_clsMutex.Unlock();
			}
		}

		if (fileFinder.IsDirectory())
		{
			// 若是目录则递归调用此方法
			StringCchCopy(lpProgressInfo->m_szStartLocation, MAX_PATH - 1, strCurrentPath);
			StringCchPrintf(
				szMsg,
				nMSG_SIZE - 1,
				_T("正在搜索[%d/%d]%s"),
				lpProgressInfo->m_nFoundCount,
				lpProgressInfo->m_nViewCount,
				strCurrentPath);
			g_clsMutex.Lock();
			lpProgressInfo->m_Update(lpProgressInfo->m_lpDlg, NULL, szMsg);
			g_clsMutex.Unlock();
			RecursiveTraverseFind(lpProgressInfo);
		}

		// 如果收到了中断信号,立即返回
		if (g_hBrokenEvent && WaitForSingleObject(g_hBrokenEvent, 5) == WAIT_OBJECT_0)
		{
			fileFinder.Close();
			return;
		}
	}

	fileFinder.Close();
}
コード例 #12
0
ファイル: gurlcache.cpp プロジェクト: deepmatrix/blaxxun-cc3d
gbool GUrlCache::GetCacheStats(const char *directory, time_t &oldest,DWORD &spaceInUse, int &filesInUse)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);


    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);
        time_t t = creationTime.GetTime();

        if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());


        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down
            GetCacheStats(path,oldest,spaceInUse,filesInUse);
        }
        else {

            DWORD length = finder.GetLength();

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            oldest = min(oldest,t);
            filesInUse++;
            spaceInUse += length;

        }


    }
    finder.Close();


    return TRUE;
}
コード例 #13
0
ファイル: gurlcache.cpp プロジェクト: deepmatrix/blaxxun-cc3d
// recursively remove a file branch
gbool GUrlCache::RemoveFiles(const char *directory,time_t olderThan)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);

    LONGLONG fileSum=0;

    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);
        time_t t = creationTime.GetTime();

        // if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());


        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down
            RemoveFiles(path,olderThan);
            RemoveDirectory(path);
        }
        else {

            DWORD length = finder.GetLength();

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            if (olderThan >0 ) {

                if (t < olderThan) {
                    if (RemoveFile(path))
                        fileSum += length;
                }


            } else {
                if (RemoveFile(path))
                    fileSum += length;
            }

        }


    }
    finder.Close();

    TRACE("%ld bytes deleted \n",(long) fileSum);

    return TRUE;
}
コード例 #14
0
ファイル: gurlcache.cpp プロジェクト: deepmatrix/blaxxun-cc3d
// add files to list
gbool GFileSorter::AddFiles(const char *directory,time_t &maxFileTime,BOOL &stop)
{

    CFileFind finder;

    CString dir = directory;

    // add separator
    int l = dir.GetLength();
    if (l == 0) return FALSE;
    if ( !((dir[l-1] == '\\') || (dir[l-1] == '/'))) dir += '\\';

    dir += "*.*";

    CString path;

    CTime creationTime((time_t)0);
    CTime accessTime((time_t)0);
    CTime writeTime((time_t)0);

    // setup the find structure
    BOOL bWorking = finder.FindFile(dir);


    while (bWorking)  { // for all entrys
        if (stop) break;

        bWorking = finder.FindNextFile();

        path = finder.GetFilePath();

        creationTime = (time_t)0;
        accessTime = (time_t)0;
        writeTime = (time_t)0;

        BOOL ret=finder.GetCreationTime(creationTime);
        finder.GetLastAccessTime(accessTime);
        finder.GetLastWriteTime(writeTime);

        time_t t = creationTime.GetTime();

        if (writeTime.GetTime()>0) t = max(t,writeTime.GetTime()); // HG wg Kristof

        if (accessTime.GetTime()>0) t = max(t,accessTime.GetTime());

        if (finder.IsDots( )) {	// ignore . ..

        } else 	if (finder.IsDirectory( )) { // recursively step down

            t=0; // we want to delete empty directories new 20.10.98
            AddFiles(path,t,stop);

            DWORD length = 0;

            // to do get date of latest
            TRACE("D %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);

            // time is the max of the child time +1
            GFSortEntry *e = new GFSortEntry(path,t+1,length,gtrue);

            if (!e) break;
            if (!Add(e)) break;

            if (t>maxFileTime) maxFileTime = t;


        }
        else {

            DWORD length = finder.GetLength(); // get length 64
            fileSum += length;

            TRACE("F %s c %ld a %ld w %ld size %ld \n",(const char *) path, creationTime.GetTime(),accessTime.GetTime(),writeTime.GetTime(),length);
            GFSortEntry *e = new GFSortEntry(path,t,length);

            if (t>maxFileTime) maxFileTime = t;

            if (!e) break;
            if (!Add(e)) break;
        }


    }
    finder.Close();

    //TRACE("%ld bytes \n",(long)fileSum);

    return TRUE;
}