On 2018-05-15 13:12, mahesh d wrote:
import glob,os

import errno

path = 'C:/Users/A-7993\Desktop/task11/sample emails/'

files = glob.glob(path)

'''for name in files:

     print(str(name))

     if name.endswith(".txt"):

            print(name)'''

for file in os.listdir(path):

     print(file)

     if file.endswith(".txt"):

         print(os.path.join(path, file))

         print(file)

         try:

             with open(file) as f:

                 msg = f.read()

                 print(msg)

         except IOError as exc:

             if exc.errno != errno.EISDIR:

                 raise


In the above program . Getting lot of errors . My intention is read the
list of the text files in a folder . Print them


  How can resolve those error

You don't say what the errors are, but I'm guessing that it's complaining that it can't find the file with trying to open it.

'open' needs the _full path_ to the file, but 'os.listdir' returns only the _name_ of the files and directories, not the full path.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to