![]() ![]() ![]() ![]() But there is only a single line to process which starts with a drive letter and so the default end of line option eol= does not need to be changed in this case.įOR executes the two commands in command block after assigning drive letter and colon to loop variable I. This default line splitting behavior is exactly what is needed here to get just drive letter and colon without the trailing spaces assigned to the loop variable I.įOR would also ignore lines by default on which first space/tab delimited string starts with a semicolon. ![]() FOR splits up by default a line into substrings using normal space and horizontal tab characters as string delimiters and assigns just first space/tab delimited string to specified loop variable I. Therefore the first line processed by FOR is the second line. The first line is skipped because of usage of option skip=1 in addition to empty lines which are always skipped by FOR on processing captured output. The output written by WMIC to handle STDOUT of background command process is captured by FOR and processed line by line after started cmd.exe terminated itself. The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which executes the embedded wmic command line with using a separate command process started in background. Read the Microsoft documentation about Using command redirection operators for an explanation of 2>nul. So executed is in background with Windows installed into directory C:\Windows: C:\Windows\System32\cmd.exe /c C:\Windows\System32\wbem\wmic.exe LOGICALDISK where VolumeName="Files" GET DeviceID 2>nulĪn error output by WMIC on no drive found with case-insensitive interpreted string Files as volume name is redirected with 2>nul from handle STDERR of background command process to device NUL to suppress it. For that reason it is necessary to escape the equal sign with ^ to be interpreted as literal character and not as separator between argument strings as usual with replacing = by a space character. The FOR command line results in starting in background one more command process with %ComSpec% /c and the command line between ' appended as additional arguments. There are also trailing spaces on both lines which cannot be seen in command prompt window, too. What can't be seen is that the output of Windows Management Instrumentation Command is Unicode encoded using encoding UTF-16 Little Endian with byte order mark (BOM) which cause often troubles as Windows command processor is designed for processing text being character encoded with one byte per character, i.e. It should be displayed something like: DeviceID I suggest to run first in a command prompt window the command line: %SystemRoot%\System32\wbem\wmic.exe LOGICALDISK where VolumeName="Files" GET DeviceID %SystemRoot%\System32\robocopy.exe "%~d0\IMPDoc" "%%I\IMPDoc" /R:1 /W:1 /NDL /NFL /NJH /NJSĮcho ERROR: Found no drive with volume name "Files". Setlocal EnableExtensions DisableDelayedExpansionįor /F "skip=1" %%I in ('%SystemRoot%\System32\wbem\wmic.exe LOGICALDISK where VolumeName^="Files" GET DeviceID 2^>nul') do ( A batch file code for copying the folder IMPDoc from drive on which the batch file is stored to a drive with volume name Files is: off ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |