-1

Hi i was going to open multiple txt files in a directory.

But i get error message of

File "testTopic.py", line 9, in <module>
with open(path +i, 'r') as f:
IOError: [Errno 2] No such file or directory:
'C:\Users\Documents\FP\TM\Export28011986676_10155756928931677.txt'

I did import os, and i trying to open files that ends with '.txt' where by my files all are 122343.txt, 344545.txt, 565464353.txt and carry on.

xxxSL
  • 121
  • 4
  • 14

2 Answers2

1

You need to add a separator between the path and the file name:

path = "C:\Users\Documents\FP\TM\Export\\"

(Mind the slash at the end of the path.)

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • i tried , but it still cant. File "testTopic.py", line 5 path = "C:\Users\Documents\FP\TM\Export\" ^ SyntaxError: EOL while scanning string literal – xxxSL Mar 11 '18 at 05:01
  • My bad, I forgot to escape the slash. – DYZ Mar 11 '18 at 05:02
0

or:

you can useing os.path.join

import os
os.path.join(path,i)
python必须死
  • 999
  • 10
  • 12