本文整理汇总了C++中qfileinfolist::iterator::isFile方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::isFile方法的具体用法?C++ iterator::isFile怎么用?C++ iterator::isFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qfileinfolist::iterator
的用法示例。
在下文中一共展示了iterator::isFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeFileWithDir
/*递归删除文件夹内容
**
**dir :文件夹的名字,绝对路径和相对路径均可
**
**返回值 :成功后返回true;否则返回false
*/
bool removeFileWithDir(const QString &dirName)
{
static QVector<QString> dirNames;
QDir dir;
QFileInfoList filst;
QFileInfoList::iterator curFi;
//初始化
dirNames.clear();
if(dir.exists()){
dirNames<<dirName;
}
else{
return true;
}
//遍历各级文件夹,并将这些文件夹中的文件删除
for(int i=0;i<dirNames.size();++i)
{
dir.setPath(dirNames[i]);
filst=dir.entryInfoList(QDir::Dirs|QDir::Files
|QDir::Readable|QDir::Writable
|QDir::Hidden|QDir::NoDotAndDotDot
,QDir::Name);
if(filst.size()>0)
{
curFi=filst.begin();
while(curFi!=filst.end())
{
//遇到文件夹,则添加至文件夹列表dirs尾部
if(curFi->isDir())
{
dirNames.push_back(curFi->filePath());
}
else if(curFi->isFile())
{
//遇到文件,则删除之
if(!dir.remove(curFi->fileName()))
{
//return false;
}
}
curFi++;
}//end of while
}
}
#if 0
//删除文件夹
for(int i=dirNames.size()-1;i>=0;--i)
{
if(!dir.rmdir(dirNames[i]))
{
//return false;
}
}
#endif
return true;
}
示例2: ReplacePakInDec
int PathManager::ReplacePakInDec(QString &path, QString &oldName, QString &newName)
{
QVector<QString> dirNames;
QDir dir(path);
QFileInfoList filst;
QFileInfoList::iterator curFi;
//初始化
dirNames.clear();
if (dir.exists()){
dirNames << path;
}
else{
return 0;
}
//遍历各级文件夹,并将这些文件夹中的文件删除
for (int i = 0; i<dirNames.size(); ++i)
{
dir.setPath(dirNames[i]);
filst = dir.entryInfoList(QDir::Dirs | QDir::Files
| QDir::Readable | QDir::Writable
| QDir::Hidden | QDir::NoDotAndDotDot
, QDir::Name);
if (filst.size()>0){
curFi = filst.begin();
while (curFi != filst.end())
{
//遇到文件夹,则添加至文件夹列表dirs尾部
if (curFi->isDir()){
dirNames.push_back(curFi->filePath());
}
else if (curFi->isFile()){
//遇到文件,则删除之
if (curFi->absoluteFilePath().toLower().endsWith(".smali")){
if (!ReplacePakNameInSmali(curFi->absoluteFilePath(), oldName, newName)){
return 1;
}
}
else if (curFi->absoluteFilePath().toLower().endsWith(".xml")){
if (!ReplacePakNameInXml(path, curFi->absoluteFilePath(), oldName, newName)){
return 1;
}
}
}
curFi++;
}//end of while
}
}
int ret = 0;
ret = RenamePakInDec(path, oldName, newName);
if (ret != 0){
return ret;
}
return 0;
}
示例3: SearchDirContianSuffix
bool PathManager::SearchDirContianSuffix(const QString &dirFrom, QStringList &result, QString &suffix)
{
QVector<QString> dirNames;
QDir dir(dirFrom);
QFileInfoList filst;
QFileInfoList::iterator curFi;
//初始化
dirNames.clear();
if (dir.exists()){
dirNames << dirFrom;
}
else{
return true;
}
//遍历各级文件夹,并将这些文件夹中的文件删除
for (int i = 0; i < dirNames.size(); ++i)
{
dir.setPath(dirNames[i]);
filst = dir.entryInfoList(QDir::Dirs | QDir::Files
| QDir::Readable | QDir::Writable
| QDir::Hidden | QDir::NoDotAndDotDot
, QDir::DirsFirst);
if (filst.size()>0){
curFi = filst.begin();
while (curFi != filst.end())
{
//遇到文件夹,则添加至文件夹列表dirs尾部
if (curFi->isDir()){
dirNames.push_back(curFi->filePath());
}
else if (curFi->isFile()){
if (curFi->fileName().endsWith(suffix)){
result.push_back(curFi->absolutePath());
break;
}
}
curFi++;
}//end of while
}
}
return true;
}
示例4: CopyDir
bool PathManager::CopyDir(const QString &source, const QString &destination, bool isCover)
{
/* 递归实现 */
/*QDir directory(source);
if (!directory.exists()){
return false;
}
QString srcPath = QDir::toNativeSeparators(source);
if (!srcPath.endsWith(QDir::separator())){
srcPath += QDir::separator();
}
QString dstPath = QDir::toNativeSeparators(destination);
if (!dstPath.endsWith(QDir::separator())){
dstPath += QDir::separator();
}
QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
for (QStringList::size_type i = 0; i != fileNames.size(); ++i)
{
QString fileName = fileNames.at(i);
QString srcFilePath = srcPath + fileName;
QString dstFilePath = dstPath + fileName;
QFileInfo fileInfo(srcFilePath);
if (fileInfo.isFile() || fileInfo.isSymLink()){
if (isCover){
QFile::setPermissions(dstFilePath, QFile::WriteOwner);
}
if (!QFile::copy(srcFilePath, dstFilePath)){
return false;
}
}
else if (fileInfo.isDir()){
QDir dstDir(dstFilePath);
dstDir.mkpath(dstFilePath);
if (!CopyDir(srcFilePath, dstFilePath, isCover)){
return false;
}
}
}
return true;*/
QVector<QString> dirNames;
QVector<QString> fileNames;
QDir dir(source);
if (!dir.exists()){
return false;
}
dirNames.clear();
dirNames << source;
QFileInfoList filst;
QFileInfoList::iterator curFi;
for (int i = 0; i < dirNames.size(); ++i)
{
dir.setPath(dirNames[i]);
filst = dir.entryInfoList(QDir::Dirs | QDir::Files
| QDir::Readable | QDir::Writable
| QDir::Hidden | QDir::NoDotAndDotDot
, QDir::DirsFirst);
if (filst.size() > 0){
curFi = filst.begin();
while (curFi != filst.end())
{
if (curFi->isDir()){
dirNames.push_back(curFi->filePath());
}
else if (curFi->isFile()){
fileNames.push_back(curFi->absoluteFilePath());
}
curFi++;
}
}
}
for (QVector<QString>::Iterator ite = dirNames.begin(); ite != dirNames.end(); ite++)
{
QDir dirSrc(source);
QDir dirDest(destination);
ite->replace(dirSrc.absolutePath(), dirDest.absolutePath());
QDir dirTmp(*ite);
if (!dirTmp.exists() && !dirTmp.mkpath(*ite)){
return false;
}
}
for (QVector<QString>::Iterator ite = fileNames.begin(); ite != fileNames.end(); ite++)
{
QDir dirSrc(source);
QDir dirDest(destination);
QString srcPath = *ite;
QString tar = ite->replace(dirSrc.absolutePath(), dirDest.absolutePath());
QFile file(tar);
if (file.exists()){
if (isCover){
if (!file.remove()){
return false;
//.........这里部分代码省略.........
示例5: ReplaceAppPakInSrc
/**********
*返回值:0成功
*1原包名不存在
*2创建包出错
*3目的包名已经存在
*4替换包名过程出错
*5替换app包名出错
***********/
int PathManager::ReplaceAppPakInSrc(QString &path, QString &oldName, QString &newName)
{
QVector<QString> dirNames;
QDir dir(path);
QFileInfoList filst;
QFileInfoList::iterator curFi;
//初始化
dirNames.clear();
if (dir.exists()){
dirNames << path;
}
else{
return 0;
}
bool isTopDir = true;
//遍历各级文件夹,并将这些文件夹中的文件删除
for (int i = 0; i<dirNames.size(); ++i)
{
dir.setPath(dirNames[i]);
filst = dir.entryInfoList(QDir::Dirs | QDir::Files
| QDir::Readable | QDir::Writable
| QDir::Hidden | QDir::NoDotAndDotDot
, QDir::Name);
if (isTopDir){
isTopDir = false;
for (int i = 0; i < filst.size(); i++)
{
if (filst[i].fileName() == "assets" || filst[i].fileName() == "bin" || filst[i].fileName() == "libs"){
filst.removeAt(i);
i--;
}
}
}
if (filst.size()>0){
curFi = filst.begin();
while (curFi != filst.end())
{
//遇到文件夹,则添加至文件夹列表dirs尾部
if (curFi->isDir()){
dirNames.push_back(curFi->filePath());
}
else if (curFi->isFile()){
if (curFi->absoluteFilePath().toLower().endsWith(".java")){
if (!ReplaceAppPakNameInJava(path, curFi->absoluteFilePath(), oldName, newName)){
return 1;
}
}
else if (curFi->absoluteFilePath().toLower().endsWith(".xml")){
if (!ReplaceAppPakNameInXml(path, curFi->absoluteFilePath(), oldName, newName)){
return 1;
}
}
}
curFi++;
}//end of while
}
}
if (!ReplaceAppPakNameInManifest(path, oldName, newName)){
return 5;
}
return 0;
}
示例6: soInfo
QString
AudioPluginOSCGUI::getGUIFilePath(QString identifier)
{
QString type, soName, label;
PluginIdentifier::parseIdentifier(identifier, type, soName, label);
RG_DEBUG << "AudioPluginOSCGUI::getGUIFilePath(" << identifier << ")";
QFileInfo soInfo(soName);
if (soInfo.isRelative()) {
//!!!
RG_DEBUG << "AudioPluginOSCGUI::AudioPluginOSCGUI: Unable to deal with relative .so path \"" << soName << "\" in identifier \"" << identifier << "\" yet";
throw Exception("Can't deal with relative .soname");
}
QDir dir(soInfo.dir());
QString fileBase(soInfo.completeBaseName());
if (!dir.cd(fileBase)) {
RG_DEBUG << "AudioPluginOSCGUI::AudioPluginOSCGUI: No GUI subdir for plugin .so " << soName;
throw Exception("No GUI subdir available");
}
QFileInfoList list = dir.entryInfoList();
// in order of preference:
const char *suffixes[] = { "_rg", "_kde", "_qt", "_gtk2", "_gtk", "_x11", "_gui"
};
int nsuffixes = int(sizeof(suffixes) / sizeof(suffixes[0]));
for (int k = 0; k <= nsuffixes; ++k) {
for (int fuzzy = 0; fuzzy <= 1; ++fuzzy) {
QFileInfoList::iterator info;
for (info = list.begin(); info != list.end(); ++info) { //### JAS Check for errors
RG_DEBUG << "Looking at " << info->fileName() << " in path "
<< info->filePath() << " for suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << ", fuzzy " << fuzzy << endl;
if (!(info->isFile() || info->isSymLink())
|| !info->isExecutable()) {
RG_DEBUG << "(not executable)";
continue;
}
if (fuzzy) {
if (info->fileName().left(fileBase.length()) != fileBase)
continue;
RG_DEBUG << "(is file base)";
} else {
if (info->fileName().left(label.length()) != label)
continue;
RG_DEBUG << "(is label)";
}
if (k == nsuffixes || info->fileName().toLower().endsWith(suffixes[k])) {
RG_DEBUG << "(ends with suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << " or out of suffixes)";
return info->filePath();
}
RG_DEBUG << "(doesn't end with suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << ")";
}
}
}
return QString();
}