Tobias P.L Wennberg e239096ef7 Fix merge
2025-01-12 09:35:41 +01:00

28 lines
555 B
Go

package rm
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
"os"
"path/filepath"
)
func Rm(in input_parser.Input, env *environment.Env) {
file_path := filepath.Join(env.Path, in.Args_raw)
stat, err := os.Stat(file_path)
if os.IsNotExist(err) {
fmt.Println(fmt.Sprintf("File does not exist"))
return
}
if stat.IsDir() {
fmt.Print(fmt.Sprintf("%s Is a folder, not a file!", file_path))
return
}
err = os.Remove(file_path)
if err != nil {
fmt.Print(fmt.Sprintf("Error removing file or folder: %s", err.Error()))
return
}
}