Python os.walk() Method with example

Syntax

os.walk(top[, topdown=True new[, onerror=None[, followlinks=False]]] )

Parameter Details

Return Value

Example

# !/usr/bin/python

import os
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))

Output

./tmp/test.py ./.bash_logout ./amrood.tar.gz ./.emacs ./httpd.conf ./www.tar.gz ./mysql.tar.gz ./test.py ./.bashrc ./.bash_history ./.bash_profile ./tmp
./.bash_logout ./amrood.tar.gz ./.emacs ./httpd.conf ./www.tar.gz ./mysql.tar.gz ./test.py ./.bashrc ./.bash_history ./.bash_profile ./tmp ./tmp/test.py

--

--

--

A tutorial blog that provides tutorials on Web Design, Programming, Java Technologies, Mobile App Development, Database, Machine Learning, etc.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Null Safety with Flutter 2.0

Load Balancing in Scylla Alternator

VS Code Mistakes You Need To Stop Making Now

Download Dj Sound Mixer App For Android

Explore the possibilities with hundreds of domain extensions — {link} -

Everything You Need To Know About Python Data Types & Variables

How I made Atom into Vim

The Pitfalls of Code Challenges

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Web Design Tutorialz

Web Design Tutorialz

A tutorial blog that provides tutorials on Web Design, Programming, Java Technologies, Mobile App Development, Database, Machine Learning, etc.

More from Medium

Generator in Python

Python File Handling

Python Basics: 09 bitwise operators

Python — Advent of Code: Day 1