Nov-29-2020, 03:41 PM
Is it possible to get the windows drive names from Cygwin?
I have a requirement to get the windows drive names from Cygwin using a python program and create a folder in one of the directories.
I am using below program to scan the number of drives in windows and create a directory in one of the drives. It works fine , but would like to achieve the same behavior when running the program from Cygwin , since Cygwin is a Linux environment it gives error for
I have a requirement to get the windows drive names from Cygwin using a python program and create a folder in one of the directories.
I am using below program to scan the number of drives in windows and create a directory in one of the drives. It works fine , but would like to achieve the same behavior when running the program from Cygwin , since Cygwin is a Linux environment it gives error for
from ctypes import windll.Following is code i am using.
import os
import string
from ctypes import windll
def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
if bitmask & 1:
drives.append(letter)
bitmask >>= 1
return drives
def create_temp_dir(drives):
newpath = drives[0]+':\\temp'
if not os.path.exists(newpath):
print " creating ", newpath
os.makedirs(newpath)
if __name__ == '__main__':
drives = get_drives()
print drives
create_temp_dir(drives)
