0

I have a problem with os.walk(path). Some folders seems that cannot Traversed. I have tried the os.path.exists(path) but i have an exception even thought the directory already exists. From documentation is written that On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.

So i have tried os.stat(path) and i get an error The system cannot find the file specified.

Finally i have tried os.listdir(path) and i get a False message. so i have tried to do the following x=os.listdir("C:\\Windows\\System32") but the folder v1 wasn't inside the list x when i have searched with the "v1" in x

the code is the following

import os

path = "C:\\Windows\\System32\\v1"
os.stat(path)

The solutions that i came across are no use to solve my problem and i want to ask is there a possible way to get permissions to execute os.stat() to that specific folder and furthermore to do it via python?

Anagnostou John
  • 498
  • 5
  • 14

1 Answers1

0

Well, you're trying to access Sys32 which is probably locked under read-only permissions. Run this as well beforehand to try to remove the read-only flag :

subprocess.check_call(["attrib", "-r", path])

Be sure to run your program as an Administrator as you're on Windows. All chmod operations are available, but are severely restricted to setting the R flags to files created by yourself and that's it. In case that fails, I'll refer you to this post, you'll have to use modules.

Milan Velebit
  • 1,933
  • 2
  • 15
  • 32