Answer the question
In order to leave comments, you need to log in
Why is the file not being copied?
I want to copy the file with the following code. He, in turn, prints error_4 invalid argument
I looked at other people's code that copies the file, it is written the same way. I would be grateful if someone could explain why this code does not work and how else to copy file X from location A to location B.
package main
import "fmt"
import "os"
import "io"
func main() {
src_path := "C:\\test_file\\"
dst_path := "C:\\test_file\\file.arj"
os.Mkdir(dst_path,1)
fsrc, err := os.Open(src_path)
if err != nil {
fmt.Println("error_2:",err)
}
defer fsrc.Close()
fdst, err := os.Create(dst_path)
if err != nil {
print("error_3",err)
}
defer fdst.Close()
size, err := io.Copy(fdst, fsrc)
if err != nil {
fmt.Println("error_4",err)
}
fmt.Println("size:",size)
}
Answer the question
In order to leave comments, you need to log in
os.Mkdir(dst_path,1)
With this line you create a folder along the path C:\test_file\file.arj
Then you try to write a file along the same path, and therefore it does not work.
You need to create the C:\test_file folder, not C:\test_file\file.arj.
PS Life hack: if you use the right quotes, you won't have to duplicate \\.
src_path := `C:\file.arj`
dst_path := `C:\test_file\file.arj`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question