Skip to content

os: Rename cannot move the file to a different disk drive #13766

@zaz600

Description

@zaz600

go version go1.5.2 windows/386

After 92c5736 with MoveFileEx os.Rename("r:\1.txt", "z:\1.txt") on windows generate error:

The system cannot move the file to a different disk drive

https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365240(v=vs.85).aspx

When moving a file, the destination can be on a different file system or volume. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.

So, syscall_windows.go Rename must be

func Rename(oldpath, newpath string) error {
    from, err := syscall.UTF16PtrFromString(oldpath)
    if err != nil {
        return err
    }
    to, err := syscall.UTF16PtrFromString(newpath)
    if err != nil {
        return err
    }
    return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions