The files
variable contain only the filenames. When trying to manipulate the files you have to add the full path:
for root, dirs, files in os.walk(base):
for f in files:
if regex.match(f):
os.remove(os.path.join(root, f))
More Related Contents:
- Using os.walk() to recursively traverse directories in Python
- How to do a recursive sub-folder search and return files in a list?
- os.walk without digging into directories below
- Filtering os.walk() dirs and files
- os.walk without hidden folders
- Travel directory tree with limited recursion depth
- Need the path for particular files using os.walk() [duplicate]
- os.walk very slow, any way to optimise?
- Selenium using Python – Geckodriver executable needs to be in PATH
- How are Python’s Built In Dictionaries Implemented?
- multiprocessing.Pool: When to use apply, apply_async or map?
- Serializing class instance to JSON
- How to install lxml on Ubuntu
- Asynchronous method call in Python?
- How do I check if stdin has some data?
- What is the difference between pandas.qcut and pandas.cut?
- Block tridiagonal matrix python
- Python Threading String Arguments
- Flask-SQLAlchemy db.create_all() raises RuntimeError working outside of application context
- How do I make a single legend for many subplots?
- Can not increment global variable from function in python [duplicate]
- How to add a background image into pygame?
- Different std in pandas vs numpy
- Difference between np.int, np.int_, int, and np.int_t in cython?
- FFT-based 2D convolution and correlation in Python
- How can I print and display subprocess stdout and stderr output without distortion?
- How to call module written with argparse in iPython notebook
- What’s the difference between %s and %d in string formatting?
- Iterating through list of list
- Python: Converting GIF frames to PNG