What does this specific .cmd file do? -
i need cmd file following content:
@echo off /f "tokens=1,4 delims= " %%a in ('dir e:\ /t:c^|findstr /i /l "v"') echo %%a %%b echo on pause
i can't figure out does.
can me?
i know output, don't know why gives me output.
here output. didn't want post @ first because windows german, sorry:
datenträger in laufwerk e: ist volume volumeseriennummer: 1ab8-6911 verzeichnis von e:\ 22.09.2015 09:09 0 282ba90118a5f80716 06.10.2015 09:07 0 32f0961d6cc71b3c51bdc6 06.10.2015 09:07 0 4f1ab9edc5ed58c95f344fd2bc84a6ec 02.02.2016 10:56 <dir> ada200fdfcff43bdf47cf363ddf8 22.09.2015 09:08 <dir> besitzer 06.10.2015 09:07 0 bf5f62260169474da0ec9df993590745 06.10.2015 09:07 0 de9afd1afa67ed193d0adb16010b54 10.10.2016 20:29 <dir> importafter 01.12.2006 22:37 904.704 msdia80.dll 03.10.2016 15:27 <dir> myxampp 08.09.2015 16:20 <dir> schule 08.09.2015 16:20 <dir> spiele 6 datei(en), 904.704 bytes 6 verzeichnis(se), 865.948.643.328 bytes frei
the .cmd file gives me output:
datenträger e: volumeseriennummer: verzeichnis 6 bytes
but why?
i explain batch code command command in order of execution line:
for /f "tokens=1,4 delims= " %%a in ('dir e:\ /t:c^|findstr /i /l "v"') echo %%a %%b
first executed command is:
dir e:\ /t:c
this command according output running in command prompt window dir /?
outputs files , directories in root directory of drive e: displaying creation date because of /t:c
instead of last modification date default.
the files , directories output on ntfs (new technology file system) formatted drives sorted alphabetically because ntfs sort important here.
on fat16, fat32 , exfat drives files , directories listed unsorted stored in file allocation table (fat). therefore usage of dir parameter /o:n
additionally needed list sorted name drive independent on file system.
the output of command dir written stdout redirected stdin of console application findstr further processing using pipe redirection operator |
. see microsoft technet article using command redirection operators details.
|
should interpreted redirection operator on execution of
dir e:\ /t:c | findstr /i /l "v"
done command for.
to achieve necessary escape |
putting ^
left of it. command interpreter cmd.exe
on parsing command line interprets |
literal character , not redirection operator because of ^
before.
if |
have been used instead of ^|
within for command line windows command interpreter exit execution of batch file on line because of syntax error redirection operator |
invalid in middle of for command line. error message on german respectively english windows:
english: | unexpected @ time.
german: "|" ist syntaktisch dieser stelle nicht verarbeitbar.
running in command prompt window findstr /?
outputs of standard windows console application. usage of /i
makes search case-insensitive. , /l
tells findstr interpret search string "v"
literal string , not regular expression. findstr should output lines containing either v
or v
.
for posted output of dir means findstr outputs:
datenträger in laufwerk e: ist volume volumeseriennummer: 1ab8-6911 verzeichnis von e:\ 6 verzeichnis(se), 865.948.643.328 bytes frei
the output of command dir filtered findstr next processed line line command for.
the for parameters "tokens=1,4 delims= "
explained in output running for /?
in command prompt window result in splitting each line several strings using space character separator strings.
the first string should assigned loop variable a
being specified next on for command line.
the fourth string should assigned next loop variable b
according ascii table.
loop variables case-sensitive because of feature assign multiple strings multiple loop variables.
all other space separated strings line of no interest , therefore ignored.
this additional line filtering command for results in output:
datenträger e: volumeseriennummer: verzeichnis 6 bytes
but quite clear output not code designed originally.
for reason let assume for command line
- is written english windows instead of german windows
(with germany selected country in windows region settings determines date/time output format dd.mm.yyyy hh:mm), - root directory of drive e: contains @ least 1 file or directory containing
v
orv
being of interest batch code writer, - the files , directories output sorted name (by ntfs) and
- output creation date instead of last modification date.
so command dir e:\ /t:c
outputs:
volume in drive e volume serial number 1ab8-6911 directory of e:\ 22.09.2015 09:09 0 282ba90118a5f80716 06.10.2015 09:07 0 32f0961d6cc71b3c51bdc6 06.10.2015 09:07 0 4f1ab9edc5ed58c95f344fd2bc84a6ec 02.02.2016 10:56 <dir> ada200fdfcff43bdf47cf363ddf8 22.09.2015 09:08 <dir> besitzer 06.10.2015 09:07 0 bf5f62260169474da0ec9df993590745 06.10.2015 09:07 0 de9afd1afa67ed193d0adb16010b54 10.10.2016 20:29 <dir> importafter 01.12.2006 22:37 904.704 msdia80.dll 03.10.2016 15:27 <dir> myxampp 08.09.2015 16:20 <dir> schule 08.09.2015 16:20 <dir> spiele 13.11.2016 12:53 <dir> veryimportantdirectory 6 file(s) 904.704 bytes 7 dir(s) 865.948.639.232 bytes frei
this output filtered findstr /i /l "v"
is:
volume in drive e volume serial number 1ab8-6911 13.11.2016 12:53 <dir> veryimportantdirectory
and 3 lines filtered next command for outputs:
volume e volume 13.11.2016 veryimportantdirectory
it can supposed first 2 lines not of interest , last line of interest original batch code writer.
the batch code written getting output:
the creation date , name of files/directories containing v
in case.
Comments
Post a Comment