I am trying to write a script package that receives (among other things) a list of all the disk drives of a computer. The main code looks something like this:
REM Build the list of disk drives to monitor SETLOCAL enabledelayedexpansion FOR /f "skip=1 tokens=1 delims=:" %%a in ('"WMIC logicaldisk WHERE drivetype=3 GET deviceid"') do ( SET "DISK_DATABASES=!DISK_DATABASES!%%a|" SET "DRIVES_TO_MONITOR=!DRIVES_TO_MONITOR!%%a:\\|" )
I am pretty explicitly creating two lists with slightly different formats for use later. However, when I run this, the output I get looks something like this:
C|D|E|| C:\\|D:\\|E:\\|:\\|
Now I expect a trailing tube in both cases, and I can handle it, but I'm really confused why there is an extra blank entry there. If I run the wmic command manually, I see that there really is an empty line at the end of the output, but I understand that /f was specifically designed to ignore empty lines.
If I turn on ECHO , it looks like the last line just comes in as a carriage return / newline or similar. Is there any way to do what I expect? Am I missing something? I tried to write an if condition in a loop to exclude this last line, but it was ... funky and never worked. I appreciate any / any help.
batch-file
Morinar Nov 04 2018-11-11T00: 00Z
source share