github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zfile/file_win.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package zfile
     5  
     6  import (
     7  	"os"
     8  	"syscall"
     9  )
    10  
    11  // MoveFile Move File
    12  func MoveFile(source string, dest string, force ...bool) error {
    13  	source = RealPath(source)
    14  	dest = RealPath(dest)
    15  	if len(force) > 0 && force[0] {
    16  		if exist, _ := PathExist(dest); exist != 0 && source != dest {
    17  			_ = os.RemoveAll(dest)
    18  		}
    19  	}
    20  	from, err := syscall.UTF16PtrFromString(source)
    21  	if err != nil {
    22  		return err
    23  	}
    24  	to, err := syscall.UTF16PtrFromString(dest)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	return syscall.MoveFile(from, to)
    29  }