
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- 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?
- How to use Glob() function to find files recursively in Python?
- How to list down all the files alphabetically using Python?
- Java program to List all files in a directory recursively
- Recursively List All Files in a Directory Including Symlinks
- How to select all child elements recursively using CSS?
- 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?
- List files recursively in C#
- How to convert PDF files to Excel files using Python?

Advertisements