Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
44 lines (34 loc) · 1.35 KB

File metadata and controls

44 lines (34 loc) · 1.35 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
from pathlib import Path
path = "F:/test/"
# for file in os.listdir(path):
# print(file)
# print('-----------------')
# print(os.path)
# print('-----------------')
# os.walk will recursively travers all files in all current and sub-directory
# root is the path of the directory that is being traversesd
# dir is the directory that are in the current directory that program is in
# files are all the files that are in the current directory
for root, dir, files in os.walk(path):
# print(f'{root} --> {dir} --> {files}\n')
for file in files:
if file.endswith('.png'):
print('------------------')
print(os.path.join(root, file))
# listing files and directory using scandir
path_2 = "/home/pankaj"
for items in os.scandir(path_2):
# st_mtime provides the time the content of the file was last modified
print(f'{items.name}--------------->{items.stat().st_mtime}')
# print(items.stat().st_mtime)
nl = '\n'
print(f'{nl}-----------------------------{nl}')
# listing files and directory using pathlib.Path
# pathlib.Path have an .itemdir() method for creating an iterator of all
# files and folders in a directory. each entry yielded by the .itemdir
# contains information about the file or directory such as name and other
# attributes.
entries = Path(path_2)
for entry in entries.iterdir():
print(entry.name)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.