Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Rename External Hard Drive Disk

Tags:

python-3.x

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"??????
like image 936
musaab Avatar asked Sep 04 '26 18:09

musaab


1 Answers

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)
like image 96
Yahya Yahyaoui Avatar answered Sep 10 '26 05:09

Yahya Yahyaoui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!