Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

python remove directory contents code example

Example 1: delete contents of directory python

import os
import glob

files = glob.glob('/YOUR/PATH/*')
for f in files:
    os.remove(f)

Example 2: python delete all files in directory

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))

Tags:

Python Example

Related

scp and rcp in linux code example change path of cli code example find all in VS code code example gcloud init console code example show mac address mac code example add several transform: code example reverse shell import pty code example small model box using html and css code example js element exists code example http.request header nodejs code example angular how to refresh installs code example what does position relative code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy