使用 stdio.h 重新定位和重命名文件C++
Relocating and renaming file C++ using stdio.h
我正在尝试使用stdio.h的rename((函数重命名文件并且它可以工作,但问题是它只能重命名位于当前项目文件夹中的文件,我希望能够选择一个目录,如果可以在此过程中从位置更改它。
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
int main()
{
bool verifier;
char oldName[] = "text.txt";
char newName[] = "newText.txt";
verifier = rename(oldName, newName);
if (!verifier)
{
std::cout << "The file has been succesfully renamedn";
}
else
{
std::cout << "There was a problem renaming the filen";
}
return 0;
}
谢谢!
默认情况下,根目录路径是运行可执行文件的位置。如果你想访问我们之外的另一个文件夹,你可以使用绝对路径(即C:/path/to/old.txt(。
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
int main()
{
char oldName[] = "C:\path\to\your\proj\text.txt"; // char oldName[] = "old.txt";
char newName[] = "C:\test\output\folder\new.txt"; // char newName[] = "newText.txt";
bool verifier = rename(oldName, newName);
if (!verifier)
{
std::cout << "The file has been succesfully renamedn";
}
else
{
std::cout << "There was a problem renaming the filen";
}
return 0;
}
相关文章:
- 如何在Visual Studio Code中重命名我的a.exe文件?
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- 以编程方式防止重命名或删除文件,但仍使其可写
- 使用 stdio.h 重新定位和重命名文件C++
- 如何检测哪些进程更改,重命名或创建文件?
- 录制后无法重命名 rosbag 文件
- 将文件重命名为已存在的文件名
- 移动了 QT 项目,重命名文件夹和项目名称,Moc'ing 返回"'-I'之后缺少值"
- 将 .c 文件重命名为 .cpp,导入 Cython 库失败
- 为什么将可执行文件重命名为临时文件的此代码段不能按预期工作?
- 如何在 C++ 中将文件从 ext4 文件系统重命名为 ntfs 文件系统
- 用C 的名称重命名文件
- 如何在C++中重命名文件
- directory_iterator file_iter重命名文件夹中的文件
- 如何使用rename()函数(c++)用字符串重命名文件
- 重命名文件夹内的文件- Unicode等效函数
- 如何使用wstring重命名文件
- 在Windows 8上用C++重命名文件
- 如何在Windows上按句柄重命名文件
- 使用readdirectorychangesc++重命名文件夹后获取旧名称和新名称