I am working with the Enron emails and they do not have a file extension. I can get the first set of code to work but I cannot in the second (see error I am getting there):
This code works (cwd stands for current working directory):
for file in glob.glob(cwd + "/*" ):
f = open(file, "r")
print(f.read())
This same code as used below does not work. I get a 'permission denied' error since, I believe, the function is trying to access the dir itself rather than the files within it. Note that I have also tried using a 'if file.endswith("*.*")' but this will not recognize the files since there is no extension:
for dirpath, dirs, files in os.walk(cwd):
for file in glob.glob(dirpath + "/*"): # I have also tried this as 'for file in glob.glob("/*")' and 'for file in glob.glob("*")'
path = os.path.join(dirpath, file)
print(os.getcwd())
f = open(file, "r")
text = f.read()
f.close()
Any idea on how to get this to work would be appreciated.
This code works (cwd stands for current working directory):
for file in glob.glob(cwd + "/*" ):
f = open(file, "r")
print(f.read())
This same code as used below does not work. I get a 'permission denied' error since, I believe, the function is trying to access the dir itself rather than the files within it. Note that I have also tried using a 'if file.endswith("*.*")' but this will not recognize the files since there is no extension:
for dirpath, dirs, files in os.walk(cwd):
for file in glob.glob(dirpath + "/*"): # I have also tried this as 'for file in glob.glob("/*")' and 'for file in glob.glob("*")'
path = os.path.join(dirpath, file)
print(os.getcwd())
f = open(file, "r")
text = f.read()
f.close()
Any idea on how to get this to work would be appreciated.