本文整理汇总了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;
}
}
}
示例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");
}
}
示例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
}
示例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
}
示例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;
}
示例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;
}
示例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");
}
}
示例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
}
}
示例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"));
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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.";
}
}
示例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!");
}
}