Answers for "check of same extension in a folder python windows"

0

check of same extension in a folder python windows

# using glob
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
    print(file) 

# using os.listdir
import os
for file in os.listdir("/mydir"):
    if file.endswith(".txt"):
        print(os.path.join("/mydir", file))
 
# using os.walk
import os
for root, dirs, files in os.walk("/mydir"):
    for file in files:
        if file.endswith(".txt"):
             print(os.path.join(root, file))
Posted by: Guest on July-27-2021

Code answers related to "check of same extension in a folder python windows"

Python Answers by Framework

Browse Popular Code Answers by Language