Den*_*nis 2 .net regex vb.net parsing
我正在编写一个程序,需要解析来自windows命令"diskpart"的输出结果,特别是在用VB.NET解析磁盘和卷信息(使用"list disk"和"list volume")时
我设法使用dos命令将diskpart输出结果转换为文本文件 diskpart /s myscript.scp > result.txt
现在在VB.NET中我需要解析'result.txt'来检索'卷号','驱动器号','驱动器标签','类型','大小'和'size_unit'到一个数组中进行进一步处理.
检索所有这些数据的最佳方法是什么?我尝试在MSDN上阅读有关.NET正则表达式(Regex)的内容,它让我感到困惑,并且不确定在我的情况下应该使用什么模式.
希望有人可以帮助我,任何替代解析方法都是受欢迎的.
*更新2013年6月26日 - 由于某些技术原因,我需要坚持使用"diskpart"并依赖它的输出结果进行解析.
输入示例(result.txt)
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: PC1
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 1863 GB 1024 KB
Disk 1 No Media 0 B 0 B
Disk 2 Online 7424 MB 0 B
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 0 E DVD-ROM 0 B No Media
Volume 1 C SYSTEM NTFS Partition 100 GB Healthy System
Volume 2 D TEMP NTFS Partition 1606 GB Healthy Pagefile
Volume 3 G Removable 0 B No Media
Volume 4 F GSFKEY NTFS Removable 7423 MB Healthy
Run Code Online (Sandbox Code Playgroud)
产量
disk(0)
.disknum=0
.size=1863
.size_unit="GB
disk(0)
.disknum=1
.size=0
.size_unit="B"
..and so on
vol(0)
.volnum=0
.letter="E"
.label=""
.type="DVD-ROM"
.size=0
.size_unit="B"
vol(1)
.volnum=1
.letter="C"
.label="SYSTEM"
.type="Partition"
.size=100
.size_unit="GB"
..and so on
Run Code Online (Sandbox Code Playgroud)
你能从System.IO.DriveInfo获得这些信息吗?
public DriveInfo(string driveName);
public long AvailableFreeSpace
public string DriveFormat
public DriveType DriveType
public DirectoryInfo RootDirectory
public long TotalFreeSpace
public long TotalSize
public string VolumeLabel
public static DriveInfo[] GetDrives();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1607 次 |
| 最近记录: |