Home python os.listdir how to properly register the path in Windows

os.listdir how to properly register the path in Windows

Author

Date

Category

Code:

path_dir = 'c: \ pat_to_dir'
  For Name in Os.listdir (path_dir):
   foo

Error:
For Name in Os.listdir (DIR):
OSERROR: [ERRNO 2] NO SUCH FILE OR DIRECTORY: ‘C: \ Path_TO_DIR’

How to register the way?


Answer 1

import os
path_dir = r'c: \ python37 '
For Name in Os.listdir (path_dir):
   Print (Name)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions