Hiya. I need assistance. In my code, the desired .txt file (with textual content) is copied within the specified path to the listing, however the code must be modified in order that solely these tapes which have a sure sequence of characters are copied to the brand new file. This may be achieved, I feel, with Graph, however I don’t know the way
I’ll be pleased about your assist
bundle foremost
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
func foremost() {
learn := make([]byte, 0, 64)
var title, name2 string
var path string
fmt.Println("Set technique to copy file: ")
fmt.Scan(&path)
fmt.Println("Set file title to repeat: ")
fmt.Scan(&title)
wd, err := os.Getwd()
if err != nil {
fmt.Println("Error:", err)
return
}
os.Chdir(path)
file, err := os.OpenFile(title, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
fmt.Println(err)
}
learn, err = ioutil.ReadFile(title)
defer file.Shut()
os.Chdir(wd)
fmt.Println("Working Listing: ", wd)
fmt.Println("Software: ", filepath.Be part of(wd, os.Args[0]))
d := filepath.Be part of(wd, "Emperor")
if err := os.Mkdir(d, 0755); err != nil {
fmt.Println("Error:", err)
}
fmt.Println("Created ", d)
if err := os.Chdir(d); err != nil {
fmt.Println("Error:", err)
}
fmt.Println("Set title")
fmt.Scan(&name2)
file2, err := os.OpenFile(name2, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
fmt.Println("failed to repeat the file")
fmt.Println(err)
}
file2.WriteString(string(learn))
fmt.Println("New Working Listing: ", d)
}