相关疑难解决方法(0)

使用SetFileInformationByHandle移动文件

我正在尝试使用移动文件SetFileInformationByHandle.Niall Douglas在他的CppCon2015谈话"赛车文件系统"中提出了这种技术,作为原子地移动/重命名文件的一种方式.但是,我很难提供正确的论据; 它总是失败并GetLastError返回ERROR_INVALID_PARAMETER.

我使用Unicode字符集通过以下设置尝试了这个:

  • VS2015U1,在Windows 10下运行exe
  • VS2015U2,在Windows Server 2012下运行exe
  • VS2013,在Windows 7下运行exe

但行为是一样的.我确保可以访问测试文件夹和测试文件.

#include <sdkddkver.h>
#include <windows.h>

#include <cstring>
#include <iostream>
#include <memory>

int main()
{
    auto const& filepath = L"C:\\remove_tests\\file.txt";
    auto const& destpath = L"C:\\remove_tests\\other.txt";
    // unclear if that's the "root directory"
    auto const& rootdir = L"C:\\remove_tests";

    // handles will be leaked but that should be irrelevant here
    auto const f_handle = CreateFile(filepath,
        GENERIC_READ | GENERIC_WRITE | DELETE,
        0,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    if …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi file-rename file-move

6
推荐指数
2
解决办法
1859
查看次数

标签 统计

c++ ×1

file-move ×1

file-rename ×1

winapi ×1

windows ×1