I am trying to delete files with a wildcard like shell scripts like:
c:\del 123_*
My trial as below was failed.
os.RemoveAll("/foo/123_*")
os.Remove("/foo/123_*")
I guess I need to use some library to use a wildcard.
What is good practice for deleting files with a wildcard?
As people mentioned wildcard is a feature of shell (e.g. Windows cmd.exe
) not OS and usually programming languages don't provide equivalent of del xyz*
. You should use Glob
function to find files you want to delete.
files, err := filepath.Glob("/foo/123_*")
if err != nil {
panic(err)
}
for _, f := range files {
if err := os.Remove(f); err != nil {
panic(err)
}
}