0

At here Get command prompt out on one line, with support from https://stackoverflow.com/users/2152082/stephan I can get output on one line, but now I have problem about Checking substring in String for each output line in command prompt.

I want to output as this:

HDD0 Samsung EVO 12345678 bytes

USB1 Apacer Sticky 77777777777 bytes

HDD2 Western 33442134566 bytes

for /f "skip=2 tokens=2 delims=," %%a in (' "wmic path Win32_DiskDrive get MediaType /format:csv" ') do (
    echo %%a
    REM I need check if it containing string Removable
    if "%%a"=="Removable" (
        echo is-USB!.
        for /f "skip=2 tokens=2,3,4 delims=," %%a in ('"wmic path Win32_DiskDrive get DeviceID,Model,Size /format:csv"') do (
            REM I need repacle "\\.\PHYSICALDRIVE" to "" in %%a
            echo USB%%a %%b - %%c >> "Disk.txt"
        )
    ) else (
        echo is-HDD!.
        for /f "skip=2 tokens=2,3,4 delims=," %%a in ('"wmic path Win32_DiskDrive get DeviceID,Model,Size /format:csv"') do (
            REM I need repacle "\\.\PHYSICALDRIVE" to "" in %%a
            echo HDD%%a %%b - %%c >> "Disk.txt"
        )
    )
)

The output is empty. Please help me. Thanks.

Orion8
  • 41
  • 9
  • Possible duplicate of [How to replace substrings in windows batch file](https://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file) – lit Jun 08 '19 at 14:02

2 Answers2

0

Cmd.exe has a limited amount of string processing. Here is a good site to consult. https://www.dostips.com/DtTipsStringManipulation.php

C:>set "S=MACH001,\\.\PHYSICALDRIVE0,WDC WD1003FZEX-00MK2A0,1000202273280"
C:>set "T=%S:\\.\PHYSICALDRIVE=%"
C:>echo %T%
MACH001,0,WDC WD1003FZEX-00MK2A0,1000202273280
lit
  • 14,456
  • 10
  • 65
  • 119
0
del /f /q "Disk.txt"
for /f "skip=2 tokens=2,3,4 delims=," %%a in ('"wmic path Win32_DiskDrive get DeviceID,Model,Size /format:csv"') do (
    set "S=%%a %%b - %%c"
    set "T=%S:\\.\PHYSICALDRIVE=%"
    echo %T% >> "Disk.txt"
)

The "Disk.txt" not exist. Where did I wrong ?.

Orion8
  • 41
  • 9