当前位置: 首页>>代码示例>>C++>>正文


C++ QDir::rename方法代码示例

本文整理汇总了C++中QDir::rename方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::rename方法的具体用法?C++ QDir::rename怎么用?C++ QDir::rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDir的用法示例。


在下文中一共展示了QDir::rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: renameLnkFiles

void PMenu::renameLnkFiles(QDir base_dir)
{
  PMenuItem *item;
  for( item = list.first(); item != 0; item = list.next() )
    {
      if( item->old_name.isEmpty() )
	continue;
      if( item->entry_type == submenu )
	{
	  if( item->real_name != item->old_name )
	    if( base_dir.exists( item->old_name ) )
	      {
		base_dir.rename( item->old_name, item->real_name );
		item->old_name = item->real_name;
	      }
	  QDir sub_dir(base_dir);
	  if( !sub_dir.cd(item->old_name) )
	    continue;
	  item->sub_menu->renameLnkFiles( sub_dir );
	}
      if( item->real_name == item->old_name || item->entry_type == separator )
	continue;
      if( base_dir.exists( item->old_name ) )
	{
	  base_dir.rename( item->old_name, item->real_name );
	  item->old_name = item->real_name;
	}
    }  
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:29,代码来源:pmenu.cpp

示例2: cutExtension

void cutExtension(long maxNum)
{
    QDir Dir;
    QString loc=QCoreApplication::applicationDirPath()+"/data/video/";
    for (int i=1;i!=maxNum;++i)
    {
        Dir.rename(loc+QString::number(i)+".avi",loc+QString::number(i));
        Dir.rename(loc+QString::number(i)+"~1.avi",loc+QString::number(i)+"~1");
    }
}
开发者ID:yuting-zhang,项目名称:EasySign,代码行数:10,代码来源:FileProcess.cpp

示例3: migrateDataDir

static void migrateDataDir() {
#ifdef Q_OS_MAC
	QString olddir = QDir::homePath() + QLatin1String("/Library/Preferences/Mumble");
#if QT_VERSION >= 0x050000
	QString newdir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
	QString newdir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
#endif
	QString linksTo = QFile::readLink(olddir);
	if (!QFile::exists(newdir) && QFile::exists(olddir) && linksTo.isEmpty()) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			if (d.cd(QDir::homePath() + QLatin1String("/Library/Preferences"))) {
				if (QFile::link(d.relativeFilePath(newdir), olddir)) {
					qWarning("Migrated application data directory from '%s' to '%s'",
					         qPrintable(olddir), qPrintable(newdir));
					return;
				}
			}
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif

// Qt4 used another data directory on Unix-like systems, to ensure a seamless
// transition we must first move the users data to the new directory.
#if defined(Q_OS_UNIX) && ! defined(Q_OS_MAC)
#if QT_VERSION >= 0x050000
	QString olddir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/data/Mumble");
	QString newdir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/Mumble");

	if (!QFile::exists(newdir) && QFile::exists(olddir)) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			qWarning("Migrated application data directory from '%s' to '%s'",
			         qPrintable(olddir), qPrintable(newdir));
			return;
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif
#endif
}
开发者ID:Breekenz,项目名称:mumble,代码行数:53,代码来源:Global.cpp

示例4: migrateDataDir

static void migrateDataDir() {
#ifdef Q_OS_MAC
	QString olddir = QDir::homePath() + QLatin1String("/Library/Preferences/Mumble");
	QString newdir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
	QString linksTo = QFile::readLink(olddir);
	if (!QFile::exists(newdir) && QFile::exists(olddir) && linksTo.isEmpty()) {
		QDir d;
		d.mkpath(newdir + QLatin1String("/.."));
		if (d.rename(olddir, newdir)) {
			if (d.cd(QDir::homePath() + QLatin1String("/Library/Preferences"))) {
				if (QFile::link(d.relativeFilePath(newdir), olddir)) {
					qWarning("Migrated application data directory from '%s' to '%s'",
					         qPrintable(olddir), qPrintable(newdir));
					return;
				}
			}
		}
	} else {
		/* Data dir has already been migrated. */
		return;
	}

	qWarning("Application data migration failed.");
#endif
}
开发者ID:Samangan,项目名称:mumble,代码行数:25,代码来源:Global.cpp

示例5: undoRename

bool Leaf::undoRename()
{
    QReadLocker locker (&lock);

    if (state->isLocked() || state->isRenameSucceeded() == Tribool::indeterminate)
        return false;

    if (!state->isRenameSucceeded()) {
        setStateReadyToRename();
        return true;
    }

    QDir dir;

    if (parentComponent)
        dir.setPath(parentComponent->fullPath());

    bool isSucceeded = dir.rename(newName, fileName);

    isSucceeded ? Log::log("undo SUCCEEDED : " + dir.absolutePath() + "/" + newName + " > " + fileName)
                : Log::log("undo ---FAILED : " + dir.absolutePath() + "/" + newName + " > " + fileName);

    locker.unlock();

    isSucceeded ? setStateReadyToRename()
                : setStateUndoFailed();

    return isSucceeded;
}
开发者ID:Takashi-Inoue,项目名称:DnFsRenamer,代码行数:29,代码来源:PathDataLeaf.cpp

示例6: save

void Engine::save() throw(PersistingException*)
{
    tracer->invoked(__func__);

    if (m_dirty) {
        tracer->sdebug(__func__) << "engine is dirty --> saving it..." << endl;

        // rename current file
        QDir path = m_fileAlbum->dirPath(true);
        QString oldFileName = m_fileAlbum->fileName();

        // create new filename
        QString basename = QFileInfo(oldFileName).baseName(true);
        QString timestamp = QDateTime::currentDateTime().toString("yyyyMMdd-hhmmsszzz");
        QString newFileName = QString("%1-%2.%3").arg(basename).arg(timestamp).arg(Constants::FILE_EXTENSION);

        tracer->sdebug(__func__) << "backing up file in directory '" << path.absPath() << "': '" << oldFileName << "' --> '" << newFileName << "'..." << endl;

        if (!path.rename(oldFileName, newFileName, false)) {
            QString msg = QString("Could not move old file '%1/%2' to '%3/%4'. Not saving file. Use 'Save As'.").arg(path.absPath()).arg(oldFileName).arg(path.absPath()).arg(newFileName);
            throw new PersistingException(
                msg,
                ""
            );
        }

        // save
        XmlWriter writer = XmlWriter(*this);
        writer.store(new QFile(m_fileAlbum->absFilePath()));
    }

    m_dirty = false;
}
开发者ID:BackupTheBerlios,项目名称:kphotobook-svn,代码行数:33,代码来源:engine.cpp

示例7: renameDir

void Desktopwidget::renameDir ()
   {
   QString path = _dir->menuGetPath ();
   QString fullPath;
   bool ok;
   QString oldName = _dir->menuGetName ();
   QModelIndex index;

   index = _dir->menuGetModelIndex ();
   if (_model->findIndex (index) != -1)
      {
      QMessageBox::warning (0, "Maxview", "You cannot rename a root directory");
      return;
      }
   QString text = QInputDialog::getText(
            this, "Maxview", "Enter new directory name:", QLineEdit::Normal,
            oldName, &ok);
   if ( ok && !text.isEmpty() && text != oldName)
      {
      QDir dir;

      QModelIndex index = _dir->menuGetModelIndex ();
      QModelIndex parent = _model->parent (index);

//       if (!_model->setData (index, QVariant (text)))
      path.truncate (path.length () - oldName.length () - 1);
      fullPath = path + "/" + text;
      if (dir.rename (path + "/" + oldName, fullPath))
         _model->refresh (parent);
//          _dir->refreshItemRename (text);  // indicates current item has new children
      else
         QMessageBox::warning (0, "Maxview", "Could not rename directory");
      }
   }
开发者ID:sglass68,项目名称:paperman,代码行数:34,代码来源:desktopwidget.cpp

示例8: renameFolder

void FileSystemWidget::renameFolder()
{
    QFileInfo info = contextFileInfo();
    if (!info.isDir()) {
        return;
    }

    QString folderName = QInputDialog::getText(m_liteApp->mainWindow(),
                                               tr("Rename Folder"),tr("Folder Name"),
                                               QLineEdit::Normal,info.fileName());
    if (!folderName.isEmpty() && folderName != info.fileName()) {
        QDir dir = contextDir();
        dir.cdUp();
#ifdef Q_OS_WIN
        QString _old = info.filePath();
        QString _new = dir.path()+"/"+folderName;
        if (!MoveFileW(_old.toStdWString().c_str(),_new.toStdWString().c_str())) {
            QMessageBox::information(m_liteApp->mainWindow(),tr("Rename Folder"),
                                     tr("Failed to rename the folder!"));
        }
#else
        if (!dir.rename(info.fileName(),folderName)) {
            QMessageBox::information(m_liteApp->mainWindow(),tr("Rename Folder"),
                                     tr("Failed to rename the folder!"));
        }
#endif
    }
}
开发者ID:screscent,项目名称:liteide,代码行数:28,代码来源:filesystemwidget.cpp

示例9: on_cmdSetName_clicked

void ConfigSettingsWidget::on_cmdSetName_clicked()
{
     auto pConnection = ((MainListView*)FrmMain::instance()->mainWidget()->widget(MainView))->model.GetConnection(id);

     auto configDir = Utils::userApplicationDataDirectory() + "/config";

        //
	QDir dir;
    dir.rename(configDir + QLatin1String ("/") + pConnection->GetName(), configDir + QLatin1String ("/") + ui.txtName->text());

	QFile file;
    file.rename(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + pConnection->GetName() + (".ovpn"), configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));

    QString sql (QString("UPDATE vpn SET \"vpn-name\" = '%1' WHERE \"vpn-id\" = %2")
                .arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(ui.txtName->text())))
                 .arg(id));

    Database::instance()->execute(sql);

    QString sql2 (QString("UPDATE vpn SET \"vpn-config\" = '%1' WHERE \"vpn-id\" = %2")
		.arg(Crypt::encodePlaintext(Database::instance()->makeCleanValue(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"))))
		.arg(id));

    Database::instance()->execute(sql2);

    pConnection->SetName(ui.txtName->text());
    pConnection->SetConfigPath(configDir + QLatin1String ("/") + ui.txtName->text() + ("/") + ui.txtName->text() + (".ovpn"));
}
开发者ID:LiTianjue,项目名称:openvpn-client,代码行数:28,代码来源:configsettingswidget.cpp

示例10: mooveFileToGeneratedFolder

bool FileManager::mooveFileToGeneratedFolder(QString in_qsFileToBeMoved)
{
    QString qdDestination = m_qsPath + "/" + m_qsGeneratedFolder;
    qDebug() << qdDestination;
    QFileInfo file(in_qsFileToBeMoved);
    QDir myDir = QDir::root();
    myDir.rename(in_qsFileToBeMoved, qdDestination + "/" + file.baseName() + "." + file.completeSuffix());
    return true;
}
开发者ID:guilhemheinrich,项目名称:QtFrancis,代码行数:9,代码来源:filemanager.cpp

示例11: Rename

static void Rename(QDir &dir, QString oldName, QString newName, QString ext)
// ----------------------------------------------------------------------------
//   Rename the file with the given extension
// ---------------------------------------------------------------------------
{
    newName += ext;
    oldName += ext;
    dir.remove(newName);
    dir.rename(oldName, newName);
}
开发者ID:c3d,项目名称:tao-3D,代码行数:10,代码来源:new_document_wizard.cpp

示例12: on_pushButtoncopy_clicked

void Widget::on_pushButtoncopy_clicked()
{
    QSqlQuery query;
    QString selectedfromdb = "SELECT absdirectory,symlinkdirectory FROM test";
    QString selectedasbd;
    QString symlinkdir;
    query.exec(selectedfromdb);
    QString move2;
    QDir movedir;
    FILE *pFile; //文件指针
    Mp3Info song;
    QByteArray ba;
    while(query.next() != 0)
    {
        selectedasbd = query.value(0).toString();
        symlinkdir = query.value(1).toString();
        //qDebug() << selectedasbd << "\n";
        //QString move1 = selectedasbd;
        move2 = ui->lineEdityuanmulu->text();
        qDebug() << move2;

        ba = selectedasbd.toAscii();//将所得文件名转换为字符//yfx0527
        const char *dirnow = ba.data();
        //printf("%s\n",dirnow);
        pFile = fopen(dirnow, "r");
        fseek(pFile, -128, SEEK_END);
        fread(&song, 1, sizeof (Mp3Info), pFile); //读取MP3文件ID3V标签
        //printf("%s\n",song.album);
        QString title = QString::fromLocal8Bit(song.title,30);
        QString artist = QString::fromLocal8Bit(song.artist,30);
        QString album = QString::fromLocal8Bit(song.album,30);
        QString year = QString::fromLocal8Bit(song.year,4);
        QString comment = QString::fromLocal8Bit(song.comment,28);

        //QString artist2 = artist.trimmed();

        QString dirmubiao = ui->lineEditmubiaomulu->text();
        int dirlong = dirmubiao.length();
        symlinkdir = symlinkdir.remove(0,dirlong + 4);
        qDebug() << symlinkdir;
        QString move3 = move2 + "/" + artist;
        qDebug() << move3;
        bool mkdir = movedir.mkdir(move3);
        QString move4 = move2 + symlinkdir;
        qDebug() << move4;
        bool rename = movedir.rename(selectedasbd , move4);
        //qDebug() << selectedasbd;
        qDebug() << mkdir << rename;
        fclose(pFile);

    }
}
开发者ID:234205367,项目名称:A-HIT-filesystem-on-Linux,代码行数:52,代码来源:widget.cpp

示例13: removeCacheDirectory

bool NimCompilerCleanStep::removeCacheDirectory()
{
    auto bc = qobject_cast<NimBuildConfiguration*>(buildConfiguration());
    QTC_ASSERT(bc, return false);
    if (!bc->cacheDirectory().exists())
        return true;
    QDir dir = QDir::fromNativeSeparators(bc->cacheDirectory().toString());
    const QString dirName = dir.dirName();
    if (!dir.cdUp())
        return false;
    const QString newName = QStringLiteral("%1.bkp.%2").arg(dirName, QString::number(QDateTime::currentMSecsSinceEpoch()));
    return dir.rename(dirName, newName);
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:13,代码来源:nimcompilercleanstep.cpp

示例14: moveToDirs

/**
 * @brief moves all movies in given path to seperate directories
 * @param path place to organize
 */
void MovieFilesOrganizer::moveToDirs(QString path)
{
    path = QDir::toNativeSeparators(path);
    QFileInfo fi(path);
    if (!fi.isDir()) {
        canceled(tr("Source %1 is no directory").arg(path));
    }

    QList<QStringList> contents;
    MovieFileSearcher *fileSearcher = new MovieFileSearcher(this);
    fileSearcher->scanDir(path, contents, false, true);
    fileSearcher->deleteLater();

    int pos = path.lastIndexOf(QDir::separator());
    QString dirName = path.right(path.length() - pos -1);
    QString fileName;
    NameFormatter *nameFormat = NameFormatter::instance(this);


    foreach (QStringList movie, contents) {
        int pos = movie.at(0).lastIndexOf(QDir::separator());
        if (!(movie.at(0).left(pos).endsWith(dirName))) {
            qDebug() << "skipping " << movie.at(0);
            continue;
        }

        fi.setFile(movie.at(0));
        fileName = fi.completeBaseName();
        QDir *dir = new QDir();

        QString newFolder;
        if (movie.length() == 1)
            newFolder = path + QDir::separator() + nameFormat->formatName(fileName);
        else if (movie.length() > 1)
            newFolder = path + QDir::separator() + nameFormat->formatName(
                        nameFormat->formatParts(fileName));
        else
            continue;

        if (!(dir->mkdir(newFolder)))
            continue;

        foreach (QString file, movie) {
            if (!dir->rename(file, newFolder +
                             QDir::separator() +
                             file.right(file.length() -
                                        file.lastIndexOf
                                        (QDir::separator()) - 1)))
                qDebug() << "Moving " << file << "to " << newFolder << " failed.";
        }
    }
开发者ID:boccman,项目名称:MediaElch,代码行数:55,代码来源:MovieFilesOrganizer.cpp

示例15: renameSession

void SessionManager::renameSession( const QString & oldName, const QString & newName )
{
    if (mCurrentSession && mCurrentSession->name() == oldName) {
        saveSessionAs(newName);
        removeSession(oldName);
    } else {
        QDir dir = sessionsDir();
        if (dir.path().isEmpty())
            return;

        if (!dir.rename(oldName + ".yaml", newName + ".yaml"))
            qWarning("Could not rename session file!");
    }
}
开发者ID:8c6794b6,项目名称:supercollider,代码行数:14,代码来源:session_manager.cpp


注:本文中的QDir::rename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。