I've seen this in most batches:
Code: Select all
for /f "delims=" %%A in ('xcopy /w "%~f0" "%~f0" 2^>nul') do (
if not defined key set "key=%%A"
)
set "key=!key:~-1!"
There is a simpe way to read the first line:
The output with file is not promt when use /Q
In destination I use "NUL:\*" - this isn't a Drive or a Location but no output for error. And the message with /L Option is anyone OK.
Code: Select all
for /F "eol=1delims=" %%x in ('xcopy /WQL "%~f0" NUL:\*') do (set "key=%%x"
set "key=!key:~-1!"
)
To read as any more input as once use an Intitialize-Token from xcopy output like this
Code: Select all
@echo off
setlocal disabledelayedexpansion
:init_token_Keypress
for /f %%n in ('echo( ^|cmd /q /u /c "for /f "eol^=1delims^=" %%E in ('xcopy /WQL "%comspec%" nul:\*') do echo(%%E"^|find /c " "') do set /a Keytoken= %%n
:Input
(
for /F "eol=1tokens=%keytoken%delims= " %%x in ('xcopy /WQL "%~f0" NUL:\*') do set "key=%%x"
)|| set "key= "
goto :Input
Phil