-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.

4
  • The code you posted does not contain the line the error message is pointing to. The code you posted has entirely different problems. Commented Mar 11, 2018 at 4:32
  • FIX the indentations first. Commented Mar 11, 2018 at 4:33
  • @user2357112 i have update my post, with a new error message Commented Mar 11, 2018 at 4:40
  • @UbdusSamad i have fixed the indentations already Commented Mar 11, 2018 at 4:40

2 Answers 2

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.)

Sign up to request clarification or add additional context in comments.

2 Comments

i tried , but it still cant. File "testTopic.py", line 5 path = "C:\Users\Documents\FP\TM\Export\" ^ SyntaxError: EOL while scanning string literal
My bad, I forgot to escape the slash.
0

or:

you can useing os.path.join

import os
os.path.join(path,i)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.