I am using the function win32api.GetVolumeInformation(path) to get the information about my external driver disk. And I need to change the name of the hard disk using python. Any suggestions?
below is the code
import win32api
DiskInfo=win32api.GetVolumeInformation("E:\\")
print("DiskName:", DiskInfo[0])
## Output: DiskName: Musaab_Disk1
## My disk Name is "Musaab_Disk1", suppose I need to rename it to "Musaab_Disk2"??????
You can try the Dos command "label" by spawning a child process
import subprocess
import win32api
disk_info_old = win32api.GetVolumeInformation("E:\\")
print("disk info old", disk_info_old)
subprocess.run(['label', 'E:Musaab_Disk2'])
disk_info_new = win32api.GetVolumeInformation("E:\\")
print("disk info new", disk_info_new)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With