本文整理汇总了C++中FindFirstFile函数的典型用法代码示例。如果您正苦于以下问题:C++ FindFirstFile函数的具体用法?C++ FindFirstFile怎么用?C++ FindFirstFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FindFirstFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vCreateFileList
BOOL CConfigMsgLogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_ChkbEnableLogOnConnect.SetCheck(m_bLogOnConnect == TRUE? BST_CHECKED : BST_UNCHECKED);
m_odStartMsgID.vSetConfigData(IDC_EDIT_STARTMSGID);
m_odStopMsgID.vSetConfigData(IDC_EDIT_STOPMSGID);
m_odStartMsgID.vSetBase(BASE_HEXADECIMAL);
m_odStopMsgID.vSetBase(BASE_HEXADECIMAL);
m_odStartMsgID.vSetSigned(false);
m_odStopMsgID.vSetSigned(false);
vCreateFileList();
if(m_eCurrBus == CAN || m_eCurrBus == J1939)
{
//Load channel combo box
m_omComboChannel.ResetContent();
if (NULL != GetICANDIL())
{
LPARAM lParam = 0;
if (S_OK == GetICANDIL()->DILC_GetControllerParams(lParam, NULL, NUMBER_HW))
{
m_unChannelCount = (UINT)lParam;
}
}
m_omComboChannel.InsertString(0, _("ALL"));
for (UINT i = 1; i <= m_unChannelCount; i++)
{
CString omChannel;
omChannel.Format("%d", i);
m_omComboChannel.InsertString(i, omChannel.GetBuffer(MAX_PATH));
}
m_omComboChannel.SetCurSel(0);
}
else if(m_eCurrBus == LIN)
{
//Load channel combo box
m_omComboChannel.ResetContent();
if (NULL != GetILINDIL())
{
LPARAM lParam = 0;
if (S_OK == GetILINDIL()->DILL_GetControllerParams(lParam, NULL, NUMBER_HW))
{
m_unChannelCount = (UINT)lParam;
}
}
m_omComboChannel.InsertString(0, _("ALL"));
for (UINT i = 1; i <= m_unChannelCount; i++)
{
CString omChannel;
omChannel.Format("%d", i);
m_omComboChannel.InsertString(i, omChannel.GetBuffer(MAX_PATH));
}
m_omComboChannel.SetCurSel(0);
}
USHORT LogBlocks = GetLoggingBlockCount();
if (LogBlocks > 0)
{
for (USHORT i = 0; i < LogBlocks; i++)
{
SLOGINFO sLogObject;
HANDLE hFind;
WIN32_FIND_DATA FindData;
CStdioFile omStdiofile;
GetLoggingBlock(i, sLogObject);
// check for valid log file
CString strTempLog = sLogObject.m_sLogFileName;
hFind = FindFirstFile(strTempLog, &FindData);
if(hFind == INVALID_HANDLE_VALUE )//file not found
{
DWORD dError = GetLastError();
if(dError == ERROR_FILE_NOT_FOUND)//file not found
{
BOOL bFileOpen = omStdiofile.Open(strTempLog,
CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
if(bFileOpen == TRUE)///file created, add in the list
{
omStdiofile.Close();
AddNewItem_GUI(sLogObject, i);
}
else //not a valid file
{
RemoveLoggingBlock(i--); //remove the old log data
LogBlocks = GetLoggingBlockCount(); //refresh the log count
}
}
else //not a valid filepath / file folder is removed
{
RemoveLoggingBlock(i--); //remove the old log data
LogBlocks = GetLoggingBlockCount(); //refresh the log count
//.........这里部分代码省略.........
示例2: GetNodeC
void TargetNode::Wildcards()
{
TargetNode *pTarget, *pTargetFile;
if ( GetType() == TARGET_PROJECT )
{
GetNodeC()->Wildcards();
GetNodeH()->Wildcards();
pTarget = GetFirstChildPRJ();
while ( pTarget )
{
pTarget->Wildcards();
pTarget= pTarget->GetNext();
}
}
else if ( GetType() == NODE_FILE_C || GetType() == NODE_FILE_H )
{
char szDrive [_MAX_DRIVE +1], szFoundDrive[_MAX_DRIVE +1];
char szDir [_MAX_DIR +1], szFoundDir [_MAX_DIR +1];
char szFname [_MAX_PATH +1], szFoundFname[_MAX_PATH +1];
char szExt [_MAX_EXT +1], szFoundExt [_MAX_EXT +1];
char szWildcardsPath [_MAX_PATH +1], szFoundFile [_MAX_DIR +1];
char szEmpty[] = "";
WIN32_FIND_DATA FileFindData;
SetAllWorkFlagsToTrue();
while ( TRUE )
{
pTargetFile = GetFirstChildTarget();
while ( pTargetFile )
{
if ( pTargetFile-> GetWorkFlag() )
{
_splitpath( pTargetFile->GetFileName(), szDrive, szDir, szFname, szExt );
if ( szFname[0] != '*' )
break;
}
pTargetFile= pTargetFile->GetNext();
}
if ( pTargetFile == NULL )
break;
pTargetFile->SetWorkFlagToFalse();
_splitpath( pTargetFile->GetFilePath(), szFoundDrive, szFoundDir, szFoundFname, szFoundExt );
strcpy( szFoundFname, "*" );
_makepath( szWildcardsPath, szFoundDrive, szFoundDir, szFoundFname, szFoundExt );
int nMatchedFiles=0, nNoMatchedFiles = 0;
HANDLE hFindFile = FindFirstFile( szWildcardsPath, &FileFindData );
if ( hFindFile != INVALID_HANDLE_VALUE )
do
{
_makepath( szFoundFile, szFoundDrive, szFoundDir, FileFindData.cFileName, szEmpty );
pTarget = GetFirstChildTarget();
while ( pTarget )
{
if ( stricmp( pTarget->GetFilePath(), szFoundFile ) == 0 )
break;
pTarget= pTarget->GetNext();
}
if ( pTarget )
{
nMatchedFiles++;
pTarget->SetWorkFlagToFalse();
}
else
nNoMatchedFiles++;
}
while ( FindNextFile( hFindFile, &FileFindData ) );
if ( nMatchedFiles && (nNoMatchedFiles==0 || (nNoMatchedFiles*100)/nMatchedFiles<=50) )
{
hFindFile = FindFirstFile( szWildcardsPath, &FileFindData );
do
{
_makepath( szFoundFile, szFoundDrive, szFoundDir, FileFindData.cFileName, szEmpty );
pTarget = GetFirstChildTarget();
while ( pTarget )
{
if ( stricmp( pTarget->GetFilePath(), szFoundFile ) == 0 )
break;
pTarget= pTarget->GetNext();
}
if ( pTarget )
pTarget->SetDeleteFlag();
else // szFoundFile is not matched to project's files, insert new one
{
char* pszPath = GetParentPRJ()->GetFilePath();
int nPathLen = strlen( pszPath );
pTargetFile = new TargetNode (szFoundFile, this, GetFirstChildTarget()->GetType());
if ( strstr( pTargetFile->GetFilePath(), pszPath) )
pTargetFile->SetFileName( pTargetFile->GetFilePath() + nPathLen);
else
pTargetFile->SetFileName( pTargetFile->GetFilePath() );
pTargetFile->SetExclusionFlag();
pTargetFile->SetWorkFlagToFalse();
}
}
while ( FindNextFile( hFindFile, &FileFindData ) );
//.........这里部分代码省略.........
示例3: pcap_findalldevs_ex
//.........这里部分代码省略.........
if (pcap_parsesrcstr(source, &type, NULL, NULL, name, errbuf) == -1)
return -1;
/* Check that the filename is correct */
stringlen = strlen(name);
/* The directory must end with '\' in Win32 and '/' in UNIX */
#ifdef _WIN32
#define ENDING_CHAR '\\'
#else
#define ENDING_CHAR '/'
#endif
if (name[stringlen - 1] != ENDING_CHAR)
{
name[stringlen] = ENDING_CHAR;
name[stringlen + 1] = 0;
stringlen++;
}
/* Save the path for future reference */
pcap_snprintf(path, sizeof(path), "%s", name);
pathlen = strlen(path);
#ifdef _WIN32
/* To perform directory listing, Win32 must have an 'asterisk' as ending char */
if (name[stringlen - 1] != '*')
{
name[stringlen] = '*';
name[stringlen + 1] = 0;
}
filehandle = FindFirstFile(name, &filedata);
if (filehandle == INVALID_HANDLE_VALUE)
{
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path);
return -1;
}
#else
/* opening the folder */
unixdir= opendir(path);
/* get the first file into it */
filedata= readdir(unixdir);
if (filedata == NULL)
{
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error when listing files: does folder '%s' exist?", path);
return -1;
}
#endif
/* Add all files we find to the list. */
do
{
#ifdef _WIN32
/* Skip the file if the pathname won't fit in the buffer */
if (pathlen + strlen(filedata.cFileName) >= sizeof(filename))
continue;
pcap_snprintf(filename, sizeof(filename), "%s%s", path, filedata.cFileName);
#else
if (pathlen + strlen(filedata->d_name) >= sizeof(filename))
continue;
示例4: GetExecutableAndArgumentTemplateByExtention
//.........这里部分代码省略.........
/* we now have the command-line. First, let's trim all the
leading whitespace. */
tmp = (LPSTR) value;
/* strip leading spaces */
while ( *tmp && isspace ( *tmp ) ) {
tmp++;
}
/* we are now at the start of the executable's path */
start = tmp;
/* if the executable is surrounded by quotes, then we want to
ignore all whitespace until we see another quote--after that
we will stop. */
quoted = ( '"' == *start );
/* step through the executable's path until we reach either
the closing quote, a whitespace character or NULL. */
if ( quoted ) {
/* skip first quote because FindFirstFile() does not
work if there are quotes surrounding a script name. */
start = ++tmp;
while ( *tmp && ( '"' != *tmp ) ) {
tmp++;
}
} else {
start = tmp;
while ( *tmp && !isspace ( *tmp ) ) {
tmp++;
}
}
/* null terminate at the closing quote, the first
whitespace character or at the end of the buffer. */
*tmp = '\0';
/* validate the executable's existence */
found = FindFirstFile (
start,
&find_data );
if ( INVALID_HANDLE_VALUE == found ) {
last_error = GetLastError ();
dprintf (
D_ALWAYS,
"GetExecutableAndArgumentsByExtention: failed to "
"locate the executable, %s, to handle files "
"with extension '*%s'. (last-error = %d)\n",
start,
extension,
last_error );
__leave;
}
/* clean-up after the script search */
FindClose ( found );
/* finally, copy the executable path */
strcpy ( executable, start );
/* if we have not already consumed the entire buffer, then
copy the rest as the arguments to the executable */
start = ++tmp;
if ( arguments && value - start < length - 1 ) {
/* strip leading space until we are at the start of the
executable's arguments */
while ( *start && isspace ( *start ) ) {
start++;
}
/* make a copy of the arguments */
strcpy ( arguments, start );
}
/* if we made it here, then we're all going to be ok */
ok = TRUE;
}
__finally {
/* propagate the last error to our caller */
SetLastError ( ok ? ERROR_SUCCESS : last_error );
};
return ok;
}
示例5: SHGetMalloc
void CBINDInstallDlg::ProgramGroup(BOOL create) {
TCHAR path[MAX_PATH], commonPath[MAX_PATH], fileloc[MAX_PATH], linkpath[MAX_PATH];
HRESULT hres;
IShellLink *psl = NULL;
LPMALLOC pMalloc = NULL;
ITEMIDLIST *itemList = NULL;
HRESULT hr = SHGetMalloc(&pMalloc);
if (hr != NOERROR) {
MessageBox("Could not get a handle to Shell memory object");
return;
}
hr = SHGetSpecialFolderLocation(m_hWnd, CSIDL_COMMON_PROGRAMS, &itemList);
if (hr != NOERROR) {
MessageBox("Could not get a handle to the Common Programs folder");
if (itemList) {
pMalloc->Free(itemList);
}
return;
}
hr = SHGetPathFromIDList(itemList, commonPath);
pMalloc->Free(itemList);
if (create) {
sprintf(path, "%s\\ISC", commonPath);
CreateDirectory(path, NULL);
sprintf(path, "%s\\ISC\\BIND", commonPath);
CreateDirectory(path, NULL);
hres = CoInitialize(NULL);
if (SUCCEEDED(hres)) {
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
sprintf(linkpath, "%s\\BINDCtrl.lnk", path);
sprintf(fileloc, "%s\\BINDCtrl.exe", m_binDir);
psl->SetPath(fileloc);
psl->SetDescription("BIND Control Panel");
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH);
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
if (GetFileAttributes("readme.txt") != -1) {
sprintf(fileloc, "%s\\Readme.txt", m_targetDir);
sprintf(linkpath, "%s\\Readme.lnk", path);
psl->SetPath(fileloc);
psl->SetDescription("BIND Readme");
hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
if (SUCCEEDED(hres)) {
WCHAR wsz[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, linkpath, -1, wsz, MAX_PATH);
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
}
CoUninitialize();
}
}
else {
TCHAR filename[MAX_PATH];
WIN32_FIND_DATA fd;
sprintf(path, "%s\\ISC\\BIND", commonPath);
sprintf(filename, "%s\\*.*", path);
HANDLE hFind = FindFirstFile(filename, &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..")) {
sprintf(filename, "%s\\%s", path, fd.cFileName);
DeleteFile(filename);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
RemoveDirectory(path);
sprintf(path, "%s\\ISC", commonPath);
RemoveDirectory(path);
}
}
示例6: ServiceStart
//.........这里部分代码省略.........
priority = ABOVE_NORMAL_PRIORITY_CLASS;
else if (!_stricmp (priority_string, "HIGH_PRIORITY_CLASS"))
priority = HIGH_PRIORITY_CLASS;
else
{
MSG (M_ERR, "Unknown priority name: %s", priority_string);
goto finish;
}
/* set log file append/truncate flag */
append = false;
if (append_string[0] == '0')
append = false;
else if (append_string[0] == '1')
append = true;
else
{
MSG (M_ERR, "Log file append flag (given as '%s') must be '0' or '1'", append_string);
goto finish;
}
/*
* Instantiate an OpenVPN process for each configuration
* file found.
*/
{
WIN32_FIND_DATA find_obj;
HANDLE find_handle;
BOOL more_files;
char find_string[MAX_PATH];
openvpn_snprintf (find_string, MAX_PATH, "%s\\*", config_dir);
find_handle = FindFirstFile (find_string, &find_obj);
if (find_handle == INVALID_HANDLE_VALUE)
{
MSG (M_ERR, "Cannot get configuration file list using: %s", find_string);
goto finish;
}
/*
* Loop over each config file
*/
do {
HANDLE log_handle = NULL;
STARTUPINFO start_info;
PROCESS_INFORMATION proc_info;
struct security_attributes sa;
char log_file[MAX_PATH];
char log_path[MAX_PATH];
char command_line[256];
CLEAR (start_info);
CLEAR (proc_info);
CLEAR (sa);
if (!ReportStatusToSCMgr(SERVICE_START_PENDING, NO_ERROR, 3000))
{
MSG (M_ERR, "ReportStatusToSCMgr #3 failed");
FindClose (find_handle);
goto finish;
}
/* does file have the correct type and extension? */
if (match (&find_obj, ext_string))
{
示例7: parseheader
void parseheader(char *path)
{
WIN32_FIND_DATA fd;
HANDLE handle;
int len = 0;
char *listpath = (char*)calloc(strlen(path)+9,sizeof(char));
FILE *list = NULL;
int listoffset = 0, listsize = 0;
strncpy(listpath, path, strlen(path)-1);
strcat(listpath,"list.txt\0");
list = fopen(listpath,"r");
free(listpath);
if(!list)
{
printf("Could not open list.txt\n");
exit(-1);
}
while(!feof(list))
{
char str[512];
fgets(str, 512, list);
listfiles++;
}
rewind(list);
offset = listfiles*8;
handle = FindFirstFile(path,&fd);
do
{
if(strcmp(fd.cFileName,".") != 0 && strcmp(fd.cFileName,"..") != 0 && strcmp(fd.cFileName,"list.txt") != 0&& !(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
FILE *infile = NULL;
char *inpath = (char*)calloc(strlen(path)+strlen(fd.cFileName)+1,sizeof(char));
if((offset%PADDING)!=0)
offset += PADDING - (offset%PADDING);
strncpy(inpath, path, strlen(path)-1);
strcat(inpath,fd.cFileName);
infile = fopen(inpath, "rb");
if(!infile)
{
printf("Could not open %s\n",inpath);
exit(1);
}
fseek(infile,0,SEEK_END);
len = ftell(infile);
fclose(infile);
fscanf(list,"%08x %08x",&listoffset, &listsize);
if(listsize == 0)
{
while(listsize == 0 && !feof(list))
{
fwrite(&offset,1,4,outfile);
fwrite(&listsize,1,4,outfile);
fscanf(list,"%08x %08x",&listoffset, &listsize);
}
}
fwrite(&offset,1,4,outfile);
fwrite(&len,1,4,outfile);
offset += len;
len = 0;
free(inpath);
}
} while(FindNextFile(handle,&fd) != 0);
fscanf(list,"%08x %08x",&listoffset, &listsize);
if(listsize == 0)
{
while(listsize == 0 && !feof(list))
{
fwrite(&offset,1,4,outfile);
fwrite(&listsize,1,4,outfile);
fscanf(list,"%08x %08x",&listoffset, &listsize);
}
}
if(!feof(list))
{
printf("Probably didn't have all of the required files\n");
}
fwrite(&offset,1,4,outfile);
fwrite(&len,1,4,outfile);
fclose(list);
}
示例8: FillListBox
static void FillListBox()
{
WIN32_FIND_DATA wfd;
HANDLE hSearch;
TCHAR szFilePath[MAX_PATH];
TCHAR szFilePathSearch[MAX_PATH];
TCHAR szFileName[MAX_PATH];
TCHAR *PatchDesc = NULL;
TCHAR PatchName[256];
int nHandlePos = 0;
TV_INSERTSTRUCT TvItem;
memset(&TvItem, 0, sizeof(TvItem));
TvItem.item.mask = TVIF_TEXT | TVIF_PARAM;
TvItem.hInsertAfter = TVI_LAST;
_stprintf(szFilePath, _T("%s%s\\"), szAppIpsPath, BurnDrvGetText(DRV_NAME));
_stprintf(szFilePathSearch, _T("%s*.dat"), szFilePath);
hSearch = FindFirstFile(szFilePathSearch, &wfd);
if (hSearch != INVALID_HANDLE_VALUE) {
int Done = 0;
while (!Done ) {
memset(szFileName, '\0', MAX_PATH);
_stprintf(szFileName, _T("%s%s"), szFilePath, wfd.cFileName);
FILE *fp = _tfopen(szFileName, _T("r"));
if (fp) {
PatchDesc = NULL;
memset(PatchName, '\0', 256);
PatchDesc = GetPatchDescByLangcode(fp, nIpsSelectedLanguage);
// If not available - try English first
if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 0);
// Simplified Chinese is the reference language (should always be available!!)
if (PatchDesc == NULL) PatchDesc = GetPatchDescByLangcode(fp, 1);
for (unsigned int i = 0; i < _tcslen(PatchDesc); i++) {
if (PatchDesc[i] == '\r' || PatchDesc[i] == '\n') break;
PatchName[i] = PatchDesc[i];
}
// Check for categories
TCHAR *Tokens;
int nNumTokens = 0;
int nNumNodes = 0;
TCHAR szCategory[256];
unsigned int nPatchNameLength = _tcslen(PatchName);
Tokens = _tcstok(PatchName, _T("/"));
while (Tokens != NULL) {
if (nNumTokens == 0) {
int bAddItem = 1;
// Check if item already exists
nNumNodes = SendMessage(hIpsList, TVM_GETCOUNT, (WPARAM)0, (LPARAM)0);
for (int i = 0; i < nNumNodes; i++) {
TCHAR Temp[256];
TVITEM Tvi;
memset(&Tvi, 0, sizeof(Tvi));
Tvi.hItem = hItemHandles[i];
Tvi.mask = TVIF_TEXT | TVIF_HANDLE;
Tvi.pszText = Temp;
Tvi.cchTextMax = 256;
SendMessage(hIpsList, TVM_GETITEM, (WPARAM)0, (LPARAM)&Tvi);
if (!_tcsicmp(Tvi.pszText, Tokens)) bAddItem = 0;
}
if (bAddItem) {
TvItem.hParent = TVI_ROOT;
TvItem.item.pszText = Tokens;
hItemHandles[nHandlePos] = (HTREEITEM)SendMessage(hIpsList, TVM_INSERTITEM, 0, (LPARAM)&TvItem);
nHandlePos++;
}
if (_tcslen(Tokens) == nPatchNameLength) {
hPatchHandlesIndex[nPatchIndex] = hItemHandles[nHandlePos - 1];
_tcscpy(szPatchFileNames[nPatchIndex], szFileName);
nPatchIndex++;
}
_tcscpy(szCategory, Tokens);
} else {
HTREEITEM hNode = TVI_ROOT;
// See which category we should be in
nNumNodes = SendMessage(hIpsList, TVM_GETCOUNT, (WPARAM)0, (LPARAM)0);
for (int i = 0; i < nNumNodes; i++) {
TCHAR Temp[256];
TVITEM Tvi;
memset(&Tvi, 0, sizeof(Tvi));
Tvi.hItem = hItemHandles[i];
Tvi.mask = TVIF_TEXT | TVIF_HANDLE;
Tvi.pszText = Temp;
Tvi.cchTextMax = 256;
SendMessage(hIpsList, TVM_GETITEM, (WPARAM)0, (LPARAM)&Tvi);
//.........这里部分代码省略.........
示例9: GetSubDirs
bool CSADirRead::GetSubDirs(CCOMList<CSADirEntry> &dir_array, const CCOMString &path)
{
CCOMString newPath;
CCOMString searchString;
searchString = path;
searchString+= "\\*.*";
try
{
#ifndef USE_WIN32_FINDFILE
struct _finddata_t c_file;
long fhandle;
if ((fhandle=_findfirst( searchString, &c_file ))!=-1)
{
// we only care about subdirs
if ((c_file.attrib & _A_SUBDIR)==_A_SUBDIR)
{
// add c_file.name to the string array
// we'll handle parents on our own
if ((strcmp(c_file.name, ".")!=0) && (strcmp(c_file.name, "..")!=0))
{
newPath = path;
newPath+= "\\";
newPath+= c_file.name;
GetSubDirs(dir_array, newPath);
dir_array.push_back(newPath);
}
}
// find the rest of them
while(_findnext( fhandle, &c_file ) == 0 )
{
if ((c_file.attrib & _A_SUBDIR)==_A_SUBDIR)
{
// we'll handle parents on our own
if ((strcmp(c_file.name, ".")!=0) && (strcmp(c_file.name, "..")!=0))
{
newPath = path;
newPath+= "\\";
newPath+= c_file.name;
GetSubDirs(dir_array, newPath);
dir_array.push_back(newPath);
}
}
}
_findclose(fhandle);
}
#else
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
if ((hFind = FindFirstFile(searchString, &FindFileData))!=INVALID_HANDLE_VALUE)
{
// we only care about files, not subdirs
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY)
{
// we'll handle parents on our own
if ((strcmp(FindFileData.cFileName, ".")!=0) && (strcmp(FindFileData.cFileName, "..")!=0))
{
newPath = path;
newPath+= "\\";
newPath+=FindFileData.cFileName;
GetSubDirs(dir_array, newPath);
dir_array.push_back(newPath);
}
}
// find the rest of them
while(FindNextFile( hFind, &FindFileData ))
{
// we only care about files, not subdirs
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY)
{
// we'll handle parents on our own
if ((strcmp(FindFileData.cFileName, ".")!=0) && (strcmp(FindFileData.cFileName, "..")!=0))
{
newPath = path;
newPath+= "\\";
newPath+=FindFileData.cFileName;
GetSubDirs(dir_array, newPath);
dir_array.push_back(newPath);
}
}
}
}
FindClose(hFind);
#endif
}
catch (...)
{
return false;
}
//.........这里部分代码省略.........
示例10: AfxGetAppSettings
void CPlaylistItem::AutoLoadFiles()
{
if (m_fns.IsEmpty()) {
return;
}
const CAppSettings& s = AfxGetAppSettings();
CString fn = m_fns.GetHead();
if (s.fAutoloadAudio && fn.Find(_T("://")) < 0) {
int i = fn.ReverseFind('.');
if (i > 0) {
const CMediaFormats& mf = s.m_Formats;
CString ext = fn.Mid(i + 1).MakeLower();
if (!mf.FindExt(ext, true)) {
CString path = fn;
path.Replace('/', '\\');
path = path.Left(path.ReverseFind('\\') + 1);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hFind = FindFirstFile(fn.Left(i) + _T("*.*"), &fd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
continue;
}
CString fullpath = path + fd.cFileName;
CString ext2 = fullpath.Mid(fullpath.ReverseFind('.') + 1).MakeLower();
if (!FindFileInList(m_fns, fullpath) && ext != ext2
&& mf.FindExt(ext2, true) && mf.IsUsingEngine(fullpath, DirectShow)) {
m_fns.AddTail(fullpath);
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
}
}
}
if (s.IsISRAutoLoadEnabled()) {
const CString& pathList = s.strSubtitlePaths;
CAtlArray<CString> paths;
int pos = 0;
do {
CString path = pathList.Tokenize(_T(";"), pos);
if (!path.IsEmpty()) {
paths.Add(path);
}
} while (pos != -1);
CString dir = fn;
dir.Replace('\\', '/');
int l = dir.ReverseFind('/') + 1;
int l2 = dir.ReverseFind('.');
if (l2 < l) { // no extension, read to the end
l2 = fn.GetLength();
}
CString title = dir.Mid(l, l2 - l);
paths.Add(title);
CAtlArray<Subtitle::SubFile> ret;
Subtitle::GetSubFileNames(fn, paths, ret);
for (size_t i = 0; i < ret.GetCount(); i++) {
if (!FindFileInList(m_subs, ret[i].fn)) {
m_subs.AddTail(ret[i].fn);
}
}
}
}
示例11: DeleteLogFiles
int DeleteLogFiles()
{
WIN32_FIND_DATA ffd;
char szDir[MAX_PATH];
char File[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
LARGE_INTEGER ft;
time_t now = time(NULL);
int Age;
// Prepare string for use with FindFile functions. First, copy the
// string to a buffer, then append '\*' to the directory name.
strcpy(szDir, GetBPQDirectory());
strcat(szDir, "\\logs\\Log_*.txt");
// Find the first file in the directory.
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
return dwError;
}
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
OutputDebugString(ffd.cFileName);
}
else
{
ft.HighPart = ffd.ftCreationTime.dwHighDateTime;
ft.LowPart = ffd.ftCreationTime.dwLowDateTime;
ft.QuadPart -= 116444736000000000;
ft.QuadPart /= 10000000;
Age = (now - ft.LowPart) / 86400;
if (Age > LogAge)
{
sprintf(File, "%s/logs/%s%c", GetBPQDirectory(), ffd.cFileName, 0);
if (DeletetoRecycleBin)
DeletetoRecycle(File);
else
DeleteFile(File);
}
}
}
while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
FindClose(hFind);
return dwError;
}
示例12: Scan_prefetch
//------------------------------------------------------------------------------
//format : http://www.forensicswiki.org/wiki/Windows_Prefetch_File_Format
DWORD WINAPI Scan_prefetch(LPVOID lParam)
{
sqlite3 *db = (sqlite3 *)db_scan;
unsigned int session_id = current_session_id;
#ifdef CMD_LINE_ONLY_NO_DB
printf("\"Prefetch\";\"file\";\"path\";\"create_time\";\"last_update\";\"last_access\";\"count\";\"exec\";\"session_id\";\"depend\";\r\n");
#endif
//check if local or not :)
HTREEITEM hitem = (HTREEITEM)SendMessage(htrv_files, TVM_GETNEXTITEM,(WPARAM)TVGN_CHILD, (LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]);
if (hitem!=NULL || !LOCAL_SCAN || WINE_OS)
{
if(!SQLITE_FULL_SPEED)sqlite3_exec(db,"BEGIN TRANSACTION;", NULL, NULL, NULL);
char tmp_file_pref[MAX_PATH],ext[MAX_PATH];
while(hitem!=NULL)
{
tmp_file_pref[0] = 0;
ext[0] = 0;
GetTextFromTrv(hitem, tmp_file_pref, MAX_PATH);
if (!strcmp("pf",extractExtFromFile(charToLowChar(tmp_file_pref), ext, MAX_PATH)))
PfCheck(session_id, db, tmp_file_pref);
hitem = (HTREEITEM)SendMessage(htrv_files, TVM_GETNEXTITEM,(WPARAM)TVGN_NEXT, (LPARAM)hitem);
}
if(!SQLITE_FULL_SPEED)sqlite3_exec(db,"END TRANSACTION;", NULL, NULL, NULL);
h_thread_test[(unsigned int)lParam] = 0;
check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan
return 0;
}
//init
if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"BEGIN TRANSACTION;", NULL, NULL, NULL);
//get system path
char path[MAX_PATH] ="%WINDIR%\\Prefetch\\*.pf";
ReplaceEnv("WINDIR",path,MAX_PATH);
char path_f[MAX_PATH];
WIN32_FIND_DATA data;
HANDLE hfic = FindFirstFile(path, &data);
if (hfic != INVALID_HANDLE_VALUE)
{
do
{
if((data.cFileName[0] == '.' && (data.cFileName[1] == 0 || data.cFileName[1] == '.')) || (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){}
else
{
strncpy(path_f,path,MAX_PATH);
path_f[strlen(path_f)-4]=0;
strncat(path_f,data.cFileName,MAX_PATH);
strncat(path_f,"\0",MAX_PATH);
PfCheck(session_id, db, path_f);
}
}while(FindNextFile (hfic,&data) && start_scan);
FindClose(hfic);
}
if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"END TRANSACTION;", NULL, NULL, NULL);
check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan
h_thread_test[(unsigned int)lParam] = 0;
return 0;
}
示例13: Map_SaveFile
/*
=======================================================================================================================
Map_SaveFile
=======================================================================================================================
*/
bool Map_SaveFile(const char *filename, bool use_region, bool autosave)
{
entity_t *e, *next;
idStr temp;
int count;
brush_t *b;
idStr status;
int len = strlen(filename);
WIN32_FIND_DATA FileData;
if (FindFirstFile(filename, &FileData) != INVALID_HANDLE_VALUE) {
// the file exists;
if (len > 0 && GetFileAttributes(filename) & FILE_ATTRIBUTE_READONLY) {
g_pParentWnd->MessageBox("File is read only", "Read Only", MB_OK);
return false;
}
}
if (filename == NULL || len == 0 || (filename && stricmp(filename, "unnamed.map") == 0)) {
CFileDialog dlgSave(FALSE,"map",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Map Files (*.map)|*.map||",AfxGetMainWnd());
if (dlgSave.DoModal() == IDOK) {
filename = dlgSave.m_ofn.lpstrFile;
strcpy(currentmap, filename);
} else {
return false;
}
}
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
if (statex.dwMemoryLoad > 95) {
g_pParentWnd->MessageBox("Physical memory is over 95% utilized. Consider saving and restarting", "Memory");
}
CWaitDlg dlg;
Pointfile_Clear();
temp = filename;
temp.BackSlashesToSlashes();
if (!use_region) {
idStr backup;
backup = temp;
backup.StripFileExtension();
backup.SetFileExtension(".bak");
if (_unlink(backup) != 0 && errno != 2) { // errno 2 means the file doesn't exist, which we don't care about
g_pParentWnd->MessageBox(va("Unable to delete %s: %s", backup.c_str(), strerror(errno)), "File Error");
}
if (rename(filename, backup) != 0) {
g_pParentWnd->MessageBox(va("Unable to rename %s to %s: %s", filename, backup.c_str(), strerror(errno)), "File Error");
}
}
common->Printf("Map_SaveFile: %s\n", filename);
idStr mapFile;
bool localFile = (strstr(filename, ":") != NULL);
if (autosave || localFile) {
mapFile = filename;
} else {
mapFile = fileSystem->OSPathToRelativePath(filename);
}
if (use_region) {
AddRegionBrushes();
}
idMapFile map;
world_entity->origin.Zero();
idMapEntity *mapentity = EntityToMapEntity(world_entity, use_region, &dlg);
dlg.SetText("Saving worldspawn...");
map.AddEntity(mapentity);
if (use_region) {
idStr buf;
sprintf(buf, "{\n\"classname\" \"info_player_start\"\n\"origin\"\t \"%i %i %i\"\n\"angle\"\t \"%i\"\n}\n",
(int)g_pParentWnd->GetCamera()->Camera().origin[0],
(int)g_pParentWnd->GetCamera()->Camera().origin[1],
(int)g_pParentWnd->GetCamera()->Camera().origin[2],
(int)g_pParentWnd->GetCamera()->Camera().angles[YAW]);
idLexer src(LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES);
src.LoadMemory(buf, buf.Length(), "regionbuf");
idMapEntity *playerstart = idMapEntity::Parse(src);
map.AddEntity(playerstart);
}
count = -1;
//.........这里部分代码省略.........
示例14: FindFiles
static void FindFiles(std::vector<std::string>& matches, const std::string& datadir, const std::string& dir, const boost::regex ®expattern, int flags)
{
#ifdef _WIN32
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile((datadir + dir + "\\*").c_str(), &wfd);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName ,"..")) {
if(!(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) {
if ((flags & FileSystem::ONLY_DIRS) == 0) {
if (boost::regex_match(wfd.cFileName, regexpattern)) {
matches.push_back(dir + wfd.cFileName);
}
}
} else {
if (flags & FileSystem::INCLUDE_DIRS) {
if (boost::regex_match(wfd.cFileName, regexpattern)) {
matches.push_back(dir + wfd.cFileName + "\\");
}
}
if (flags & FileSystem::RECURSE) {
FindFiles(matches, datadir, dir + wfd.cFileName + "\\", regexpattern, flags);
}
}
}
} while (FindNextFile(hFind, &wfd));
FindClose(hFind);
}
#else
DIR* dp;
struct dirent* ep;
if (!(dp = opendir((datadir + dir).c_str()))) {
return;
}
while ((ep = readdir(dp))) {
// exclude hidden files
if (ep->d_name[0] != '.') {
// is it a file? (we just treat sockets / pipes / fifos / character&block devices as files...)
// (need to stat because d_type is DT_UNKNOWN on linux :-/)
struct stat info;
if (stat((datadir + dir + ep->d_name).c_str(), &info) == 0) {
if (!S_ISDIR(info.st_mode)) {
if ((flags & FileSystem::ONLY_DIRS) == 0) {
if (boost::regex_match(ep->d_name, regexpattern)) {
matches.push_back(dir + ep->d_name);
}
}
} else {
// or a directory?
if (flags & FileSystem::INCLUDE_DIRS) {
if (boost::regex_match(ep->d_name, regexpattern)) {
matches.push_back(dir + ep->d_name + "/");
}
}
if (flags & FileSystem::RECURSE) {
FindFiles(matches, datadir, dir + ep->d_name + "/", regexpattern, flags);
}
}
}
}
}
closedir(dp);
#endif
}
示例15: CompleteFilename
//.........这里部分代码省略.........
else
i++;
}
/* clear it out */
memset(szSearchPath, 0, sizeof(szSearchPath));
/* Start the search for all the files */
GetFullPathName(szBaseWord, MAX_PATH, szSearchPath, NULL);
/* Got a device path? Fallback to the the current dir plus the short path */
if (szSearchPath[0] == _T('\\') && szSearchPath[1] == _T('\\') &&
szSearchPath[2] == _T('.') && szSearchPath[3] == _T('\\'))
{
GetCurrentDirectory(MAX_PATH, szSearchPath);
_tcscat(szSearchPath, _T("\\"));
_tcscat(szSearchPath, szBaseWord);
}
if (StartLength > 0)
{
_tcscat(szSearchPath,_T("*"));
}
_tcscpy(LastSearch,szSearchPath);
_tcscpy(LastPrefix,szPrefix);
}
else
{
_tcscpy(szSearchPath, LastSearch);
_tcscpy(szPrefix, LastPrefix);
StartLength = 0;
}
/* search for the files it might be */
hFile = FindFirstFile (szSearchPath, &file);
if (hFile == INVALID_HANDLE_VALUE)
{
/* Assemble the orginal string and return */
_tcscpy(strOut,szOrginal);
return;
}
/* aseemble a list of all files names */
do
{
FileName * oldFileList = FileList;
if (!_tcscmp (file.cFileName, _T(".")) ||
!_tcscmp (file.cFileName, _T("..")))
continue;
/* Don't show files when they are doing 'cd' or 'rd' */
if (!ShowAll &&
file.dwFileAttributes != 0xFFFFFFFF &&
!(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
continue;
}
/* Add the file to the list of files */
FileList = cmd_realloc(FileList, ++FileListSize * sizeof(FileName));
if (FileList == NULL)
{
/* Don't leak old buffer */
cmd_free(oldFileList);
/* Assemble the orginal string and return */