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?
filepath.Glob.*is a feature of the shell, not one of the file system. So you have to go through the list of files and test their names against a pattern. Theregexppackage can deal with complicated patterns, howeverstrings.HasPrefix(str, prefix)can do the task at hand quite well.