bbash/command/rm/rm.go
2025-01-14 17:05:53 +01:00

32 lines
617 B
Go

package rm
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
"os"
"path/filepath"
"slices"
)
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) {
if slices.Contains(in.Flags, "t") {
return
}
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
}
}