Create a new directory based on the path and name entered and copy the file there, the path and name of which is specified by the user from the console (terminal) – Getting help

Greetings. Could you help me. How can I enter the path where a new directory will be created and copy the specified file from another file folder
package main

All I did was create a directory in the same location as the program.

import (
	"fmt"
	"os"
	"path/filepath"
)

func main() {
	wd, err := os.Getwd()
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("Working Directory:", wd)
	fmt.Println("Application:", filepath.Join(wd, os.Args[0]))
	d := filepath.Join(wd, "test")
	if err := os.Mkdir(d, 0755); err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println("Created", d)
	if err := os.Chdir(d); err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println("New Working Directory:", d)
}


Leave a Comment