Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

# find all text files in directory or any type of files in directory

# find all text files in directory or any type of files in directory
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.txt"):
    print(file)
    
or

import os
for file in os.listdir("/mydir"):
    if file.endswith(".txt"):
        print(os.path.join("/mydir", file))
        
or

import glob
glob.glob('./*.txt')


for root, dirs, files in os.walk(directory):
    for file in files:
        if file.endswith('.txt'):
            print(file)
Source by ss64.com #
 
PREVIOUS NEXT
Tagged: #find #text #files #directory #type #files #directory
ADD COMMENT
Topic
Name
7+1 =