Linux环境下bool QFile::rename

bool QFile::rename(const QString &newName)

1、Renames the file currently specified by fileName() to newName. Returns true if successful; otherwise returns false.

重命名当前指定的文件名。如果成功返回 true ,其他返回 false

2、If a file with the name newName already exists, rename() returns false (i.e., QFile will not overwrite it).

如果新命名的文件已经存在,函数将返回 false。(QFile 不会覆盖它)

3、The file is closed before it is renamed.

当需要重命名文件的时候,这个文件必须为关闭状态。

4、If the rename operation fails, Qt will attempt to copy this file's contents to newName, and then remove this file, keeping only newName. If that copy operation fails or this file can't be removed, the destination file newName is removed to restore the old state.

如果重命名操作失败,Qt 将会尝试拷贝改文件的内容至新文件,然后删除旧文件。如果拷贝操作失败或旧文件不能够被删除,将删除新文件以保持旧文件的状态。

例:

QString strAbsPath = "/home/test.txt";
QFile file(strAbsPath);
file.rename("/home/test1.txt");

注意:

1、传入参数必须为目标路径+文件名,修改路径也应该是目标路径+文件名。若直接传入文件名,QFile将会根据环境变量寻找改文件,rename时也会将其储存至环境变量定义的路径。

2、bool QFile::rename(const QString &oldName, const QString &newName)     (静态重载函数)

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暖晴的天

予人玫瑰,手有余香

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值