0

How can i check the read/ write permission of the file storing media? ie assume i have to write some file inside a directory and that directory may be available on read only media like (cd or dvd)or etc. So how can i check that storing media ( cd, hard disk) having a read only or read write both permission.

I am using windows xp os.

Thanks.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75
mukul sharma
  • 177
  • 2
  • 13

3 Answers3

3

Use the os.access(path, mode) function. It should be much more portable than the win32api function. Though, I have no experience with it on non-POSIX systems.

On the other hand, why don't you just try to write the file and handle exception appropriately?

Jacek Konieczny
  • 8,283
  • 2
  • 23
  • 35
1
import os
from stat import *

if S_IMODE(os.stat(dir_name)) & S_IWRITE != 0:

is more portable, if not necessarily more readable.

msw
  • 42,753
  • 9
  • 87
  • 112
0

Use the win32api.GetFileAttributes method.

P.S. also see this SO question

Community
  • 1
  • 1
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412