Home

Published

- 1 min read

python delete all files in directory

img of python delete all files in directory

The solution for this is noted below

python delete all files in directory

Solution

   import os

filelist = [ f for f in os.listdir(mydir) if f.endswith(".bak") ]
for f in filelist:
    os.remove(os.path.join(mydir, f))

Try other methods by searching on the site. That is if this doesn’t work