

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to touch all the files recursively using Python?
To touch all the files recursively, you need to walk the directory tree using os.walk and add touch all the files in it using os.utime(path_to_file).
example
import os # Recursively walk the tree for root, dirs, files in os.walk(path): for file in files: # Set utime to current time os.utime(os.path.join(root, file))
In Python 3.4+, you can directly use the pathlib module to touch files.
example
from pathlib import Path import os # Recursively walk the tree for root, dirs, files in os.walk(path): for file in files: Path(os.path.join(root, file)).touch()
- Related Questions & Answers
- How to rename multiple files recursively using Python?
- Java program to delete all the files in a directory recursively (only files)
- How to Recursively Search all Files for Strings on a Linux
- How to close all the opened files using Python?
- Java program to List all files in a directory recursively
- How to list down all the files alphabetically using Python?
- How to use Glob() function to find files recursively in Python?
- List files recursively in C#
- How to create a directory recursively using Python?
- How to remove a directory recursively using Python?
- How to zip a folder recursively using Python?
- How to extract all the .txt files from a zip file using Python?
- How to convert PDF files to Excel files using Python?
- How to download all pdf files with selenium python?
- How to remove swap files using Python?
Advertisements