I'm on my very last challenge before wrapping up this project's coding. I am trying to filter the output from diskpart's list partition and list volume commands without using temporary files.
I have the solution:
set /A hdd= 0
rem Use this for the partition listing:
set cmd="echo select disk %hdd%^&list partition| diskpart"
rem and this for the volume listing (doesn't need the select disk):
set cmd="echo select disk %hdd%^&echo list volume | diskpart"
for /F "skip=7 usebackq delims=" %%? in (`!cmd!`) do (
set line=%%?
set cut=!line:~0,8!
if NOT !cut!==DISKPART echo %%?
)
echo.
pause
There is probably a way to combine the 2 set lines inside the for loop into one, perhaps even reduce all 3 lines inside the loop into a single line, but all my attempts failed.
Here is an example of what the output looks like:
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 Primary 1000 MB 1024 KB
Partition 2 Primary 78 GB 1001 MB
Partition 0 Extended 29 GB 79 GB
Or for the volume listing:
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- ------
Volume 0 B DVD-ROM 0 B No Media
Volume 1 D DVD-ROM 0 B No Media
Volume 2 C Windows 7 U NTFS Partition 78 GB Healthy System
Seems like a simple enough thing to do conceptually, but there's very little that's simple about the numerous syntactical quirks of batch!
This question boils down to how to reduce the lines within the for loop.
Thanks for any suggestions you may have.