QT文件夹定位(网友提供)

#ifndef FOLDERFINDER_H

#define FOLDERFINDER_H
#include <QDir>
class FolderFinder
{
public:
    QString absoluteFolderPath; //要转换的绝对路径
    QString FolderPath; //要定位的文件夹名称
    FolderFinder(const QString & filePath,const QString & folderPath)
    {
        FolderPath=folderPath;
    RecursiveFolder(filePath);
    }
private:
    QString getAbsolutePathFrom(const QString & filePath)
    {
        QDir tempInfo;
        QString absoluteFilePath=tempInfo.absoluteFilePath(filePath).replace("/./","/"); //获取绝对路径
    return absoluteFilePath;
    }
    void RecursiveFolder(const QString & path)
    {
        QDir dir(path);
       // dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
       // dir.setSorting(QDir::Size | QDir::Reversed);
        QFileInfoList list = dir.entryInfoList();
        for (int i = 0; i < list.size(); ++i) {
            QFileInfo fileInfo = list.at(i);
            if(fileInfo.fileName()=="." || fileInfo.fileName()=="..")
            {
                    i++;
                    continue;
            }
            if(fileInfo.isDir())
            {
             if(fileInfo.fileName()==FolderPath)
             {
                 absoluteFolderPath=getAbsolutePathFrom(fileInfo.filePath());
                 break;
             }
            RecursiveFolder(fileInfo.filePath());
            }
        }
    }
};
#endif // FOLDERFINDER_H
使用方法

FolderFinder folder("C:\\qtconsoletest-build-desktop","Politics"); //初始递归路径

cout<<qPrintable(QString("%1").arg(folder.absoluteFolderPath));

###
QStringList items; items << "All" << "Weekend Plus" ; ui->listWidgetTimeSet->addItems(items);

QListWidgetItem* all_item = new QListWidgetItem( "All" );
QListWidgetItem* wp_item = new QListWidgetItem( "Weekend Plus" );
listWidgetTimeSet->addItem( all_item );
listWidgetTimeSet->addItem( wp_item ); listWidgetTimeSet->setCurrentItem( wp_item );

上一篇:cookie的路径决定服务器在发送请求时候 是否决定发送 当路径匹配时候 则发送给服务器(默认发送原则)


下一篇:HTTPS协议下Fiddler抓包