I use some code similar to the lines below. The rename can fail if the directory is blocked because some application has a file open in it.
err := os.Rename("C:/temp/inUse", "c:/temp/Renamed")
if err != nil {
fmt.Println(err)
...
}
I am able to detect this fact when I check err
for this content:
rename C:/temp/inUse c:/temp/Renamed: Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.
(which translates to "The process is unable to access the file because it is used by a different process") But this message varies depending on the OS language.
Is it possible to detect the problem by a unique "error code" ? I wouldn't mind if the solution is specific to Windows and doesn't work on other operating systems supported by Go.
Ideally I could do something like if err.Err == 32 { fmt.Println( "Your directory is in use please ...