void CMedoRecordManager::createPath(const QString &path) { qDebug() << Q_FUNC_INFO; QDir oDir(path); if (oDir.exists()) { qDebug() << "alreadly create PATH !!!"; return; } if (oDir.mkdir(oDir.path())) { chmod(oDir.path().toLocal8Bit().data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); qDebug() << "success to make PATH : " << oDir.path(); } else { qDebug() << "fail to make PATH : " << oDir.path(); } }
bool CSys::GetFilesInDir_( const char* pcDir, const char *pcFile, CArray<CStr> *poArray ) { WIN32_FIND_DATA oFD; CStr oDir( pcDir ); CStr oMask( oDir + pcFile ); HANDLE hFind = FindFirstFile( oMask.GetData(), &oFD ); if( hFind == INVALID_HANDLE_VALUE ) return false; do { poArray->Append( oDir + CStr( oFD.cFileName ) ); } while( FindNextFile( hFind, &oFD ) != 0 ); const DWORD dwError = GetLastError(); FindClose( hFind ); return ( dwError == ERROR_NO_MORE_FILES ); }
bool DkBatchConfig::isOk() const { if (mOutputDirPath.isEmpty()) return false; QDir oDir(mOutputDirPath); if (!oDir.exists()) { if (!oDir.mkpath(".")) return false; // output dir does not exist & I cannot create it } if (mFileList.empty()) return false; if (mFileNamePattern.isEmpty()) return false; return true; }
QStringList LPGUtils::revertDir(QString oldPath, QString newPath){ //Note: this is a recursive function and can take quite a while to perform lots of file copies //Load the directories and create it if necessary QDir oDir(oldPath); QDir nDir(newPath); bool ok=true; if( !nDir.exists() ){ //Create the new Directory qDebug() << "Re-Create parent directory structure:" << newPath; nDir.cdUp(); ok = nDir.mkpath(newPath.section("/",-1)); //also create all parent directories if necessary if(ok){ qDebug() << " - Reset permissions on the main parent dir to match snapshot"; nDir.cd(newPath.section("/",-1)); QFile::setPermissions(newPath, QFile::permissions(oldPath)); //make sure the new dir has the old permissions QFileInfo FI(oldPath); system( QString("chown "+FI.owner()+":"+FI.group()+" "+newPath).toUtf8() ); } } //Get a list of any files that error QStringList errors; if(!ok){ errors << newPath; return errors; } //Get a list of all the files in the old dir and copy them over QStringList fList = oDir.entryList(QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot, QDir::Name); for(int i=0; i<fList.length(); i++){ if( !revertFile(oldPath+"/"+fList[i], newPath+"/"+fList[i]) ){ errors << newPath+"/"+fList[i]; } } //Now list all the directories in the old dir and recursively copy them over fList = oDir.entryList(QDir::Dirs | QDir::Hidden | QDir::NoDotAndDotDot, QDir::Name); for(int i=0; i<fList.length(); i++){ QStringList errs = revertDir(oldPath+"/"+fList[i], newPath+"/"+fList[i]); if( !errs.isEmpty() ){ errors << errs; } } return errors; }
void rpnoc::Profile::setUser( QString iUser ) { mUser = iUser; QStringList oFilters; oFilters << "*.xml"; QDir oDir( "profiles/" + getUser() ); if( !oDir.exists() ) { log_e( "Directory does not exist: '" + oDir.currentPath() + "'." ); } oDir.setFilter( QDir::Files ); oDir.setNameFilters( oFilters ); oDir.setSorting( QDir::Name ); QFileInfoList oFileInfoList = oDir.entryInfoList(); for(int i = 0; i < oFileInfoList.size(); ++i){ QFileInfo oFileInfo = oFileInfoList.at(i); if(oFileInfo.fileName() != (getUser() + ".xml")){ profileList << ( QString( "%1" ).arg( oFileInfo.fileName() ) ); } } showProfiles(); }
// http://www.gamedev.net/community/forums/topic.asp?topic_id=132523 // http://ubuntuforums.org/archive/index.php/t-659718.html bool CSys::GetFilesInDir_( const char* pcDir, const char *pcFile, CArray<CStr> *poArray ) { CStr oDir( pcDir ); CArray<CStr> oArrToken; if( oDir[oDir.GetSize() - 1] != '/' ) oDir += '/'; DIR * poDir = ::opendir( pcDir ); if( !poDir ) { ::fprintf( stderr, "Unable to open the directory.\n" ); return false; } struct dirent *d = 0; while( ( d = ::readdir( poDir ) ) != 0 ) { CStr oName( d->d_name ); if ( oName == "." || oName == ".." ) continue; if ( d->d_type == 4 ) // skip directories continue; const char *wild = pcFile; const char *string = oName.GetData(); //static int wild_test( const char *wild, const char *string ) { const char *cp = NULL, *mp = NULL; while( (*string) && (*wild != '*')) { if( ( *wild != *string ) && (*wild != '?') ) { return 0; } ++wild; ++string; } while (*string) { if (*wild == '*') { if (!*++wild) { return 1; } mp = wild; cp = string+1; } else if ((*wild == *string) || (*wild == '?')) { wild++; string++; } else { wild = mp; string = cp++; } } while (*wild == '*') { ++wild; } //return !*wild; if( !*wild ) poArray->Append( oDir + oName ); } } ::closedir( poDir ); return true; }