I have the below code that copies a text file from a directory to another with overwriting the file if exists What I'm looking for is to copy the file to the destination directory without overwriting, but keep both files. As in Windows for example, a copy of a file named "test" many times would be test test - Copy test - Copy (2) test - Copy (3) text text- Copy text- Copy (2) text- Copy (3) Any help would be appreciated ?
package main import ( "fmt" "io/ioutil" "log" ) func main() { src := "./word1.txt" dest := "./words2.txt" bytesRead, err := ioutil.ReadFile(src) if err != nil { log.Fatal(err) } err = ioutil.WriteFile(dest, bytesRead, 0644) fmt.Println("Copied file \n") if err != nil { log.Fatal(err) } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)