Stack Overflow community! I'm trying to write some code to extract all .txt files from a folder in my files directory, using os.walk. But it isn't working for some reason - it isn't extracting any text because "the file doesn't exist" and os.walk is only extracting 8 files.
#import data
import os
rootDir = '/content/drive/MyDrive/HighLowQualityCounseling/transcripts'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
for fname in fileList:
print('%s' % fname)
for fname in fileList:
myfile = open(fname, "rt")
contents = myfile.read()
myfile.close()
print(contents) ###
How should I go about fixing this? Thank you so much!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…