获取电脑盘符 tcy
生活随笔
收集整理的這篇文章主要介紹了
获取电脑盘符 tcy
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
你可在dos或python中獲取電腦盤符?
import os,subprocess,re from subprocess import PIPEdef DiskSymbol():#獲取系統盤符"""dos:cwdC:\Users\Administrator > echo list volume>t1.txt && diskpart /s t1.txt && del t1.txt結果顯示:Microsoft DiskPart 版本 10.0.18362.1Copyright (C) Microsoft Corporation.在計算機上: MS-UXVPOIUPAFTI卷 ### LTR 標簽 FS 類型 大小 狀態 信息---------- --- ----------- ----- ---------- ------- --------- --------卷 0 C NTFS 磁盤分區 111 GB 正常 系統卷 1 D 系統 NTFS 磁盤分區 350 GB 正常卷 2 E 軟件 NTFS 磁盤分區 291 GB 正常卷 3 F 文檔 NTFS 磁盤分區 290 GB 正常卷 4 G FAT32 可移動 57 GB 正常"""name=r'tmp.txt'path=r'C:\Users\Administrator'filename=os.path.join(path,name)while os.path.isfile(filename):name=name+namefilename=os.path.join(path,name)orderstr=r'echo list volume>%s && diskpart /s %s && del %s'%(name,name,name)p=subprocess.Popen(orderstr,shell=True,stdin=PIPE,stdout=PIPE,stderr=PIPE,text=True,cwd=path,encoding='CP936')out,err=p.communicate()out=re.split(r'\n',out)result=[]for v in out:lst=re.findall(r'\s+([a-zA-Z]){1}\s+',v)if lst:result.append(lst[0])return result #['C', 'D', 'E', 'F', 'G']print(DiskSymbol())?
總結
以上是生活随笔為你收集整理的获取电脑盘符 tcy的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022年1月7日对自己近况的一次总结
- 下一篇: 爱情.信仰.死亡