文件重命名(C++源码)

1、调用示例

cpp 复制代码
    // 调用示例
    // 文件重命名
    std::wstring strOldFileName = L"E:\\test.json";
    std::wstring strNewFileName = L"E:\\testNew.json";
    BOOL bReplaceIfExists = FALSE;
    BOOL ret = MyFileUtil::ReNameFile(strOldFileName, strNewFileName, bReplaceIfExists);
    std::cout << "ret:" << ret <<std::endl;

2、源码

cpp 复制代码
BOOL MyFileUtil::ReNameFile(const std::wstring& strOldFileName, const std::wstring& strNewFileName, BOOL bReplaceIfExists)
{
    if (strOldFileName.empty() || strNewFileName.empty())
    {
        return FALSE;
    }

    DWORD dwFlags = MOVEFILE_COPY_ALLOWED;
    if (bReplaceIfExists)
    {
        dwFlags |= MOVEFILE_REPLACE_EXISTING;
    }
    return ::MoveFileExW(strOldFileName.c_str(), strNewFileName.c_str(), dwFlags);
}
相关推荐
奔跑的web.1 天前
TypeScript Enum 类型入门:从基础到实战
前端·javascript·typescript
BHXDML1 天前
第七章:类与对象(c++)
开发语言·c++
盐真卿1 天前
python2
java·前端·javascript
梦梦代码精1 天前
BuildingAI vs Dify vs 扣子:三大开源智能体平台架构风格对比
开发语言·前端·数据库·后端·架构·开源·推荐算法
yyf198905251 天前
C++ 跨平台开发的挑战与应对策略
c++
seabirdssss1 天前
《bootstrap is not defined 导致“获取配置详情失败”?一次前端踩坑实录》
前端·bootstrap·html
又见野草1 天前
C++类和对象(中)
开发语言·c++
kgduu1 天前
js之表单
开发语言·前端·javascript
hellokandy1 天前
C++ 如何知道程序最多可以申请多少内存
c++·vector·cin·cout
呉師傅1 天前
东芝3525AC彩色复印机CC219测试页打印方法【实际操作】
运维·网络·windows·计算机外设·电脑