views:

179

answers:

2

Hi SO community!

I searched a while but found nothing that helped me. Is there a way to check whether a drive letter stands for a shared drive/network drive or a local disc in python? I guess there is some windows api function that gives me that info, but I cant find it. Perhaps there is even a method already integrated in python?

What I am looking for is something with this or similar behaviour:

someMagicMethod("C:\\")  #outputs True 'is a local drive'
someMagicMethod("Z:\\")  #outputs False 'is a shared drive'

That would help me as well:

someMagicMethod2()  #outputs list of shared drive letters

Thanks a lot in advance!

+3  A: 

The GetDriveType function in win32file module may help you - it's a wrapper for the GetDriveType WINAPI function.

import win32file
isNetworkDrive = win32file.GetDriveType("Z:\\") == win32file.DRIVE_REMOTE

You'd be able to enumerate all with the GetLogicalDriveStrings() function in the win32api module, then use a loop to pick out only the network drives.

Charlie Somerville
Great thats just what I was searching for! Thanks a lot!
Philip Daubmeier
A: 

Hi Boys But When I Use GetDriveType in Delphi 7 My Antivirus (Mcafee 8.5) Show An Alaram And Delete The EXE File of Project. What Can I Do For This problem.

Mehran
Please ask a new question. Click 'Ask question' in the top right corner. Stackoverflow is not a discussion board but a question-and-answer website.
Philip Daubmeier