how to see directory from os module

Solutions on MaxInterview for how to see directory from os module by the best coders in the world

showing results for - "how to see directory from os module"
Chloé
28 Jan 2016
1import os
2
3# detect the current working directory
4path = os.getcwd()
5
6# read the entries
7with os.scandir(path) as listOfEntries:
8    for entry in listOfEntries:
9        # print all entries that are files
10        if entry.is_file():
11            print(entry.name)
12
Flo
20 Apr 2018
1import pathlib
2
3# define the path
4currentDirectory = pathlib.Path('.')
5
6# define the pattern
7currentPattern = "*.py"
8
9for currentFile in currentDirectory.glob(currentPattern):
10    print(currentFile)
11
Lola
21 Apr 2020
1#! /bin/bash
2
3for filename in *.py; do
4    echo "$filename:"
5    cat $filename | python3 -m timeit
6    echo " "
7done
8
Salomé
19 Apr 2020
1
2import pathlib
3
4# define the path
5currentDirectory = pathlib.Path('.')
6
7for currentFile in currentDirectory.iterdir():
8    print(currentFile)
9