Calling rm from subprocess using wildcards does not remove the files

后端 未结 3 1292
有刺的猬
有刺的猬 2020-12-15 07:29

I\'m trying to build a function that will remove all the files that start with \'prepend\' from the root of my project. Here\'s what I have so far

def cleanu         


        
3条回答
  •  有刺的猬
    2020-12-15 07:53

    I would try something like this (which also works on Windows, though I'm guessing that's not a concern for you:

    def cleanup(prepend):
        prepend = str(prepend)
        PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
        for file_to_delete in [file for file in os.listdir(PROJECT_ROOT) if file.startswith(prepend)]:
            os.remove(file_to_delete)
    

提交回复
热议问题