batch-file

Parse WMIC output to set returned value as a variable (windows batch)

北城余情 提交于 2021-02-13 17:37:54
问题 I have the following command: c:\wmic baseboard get Manufacturer Manufacturer ASUSTeK Computer INC. I'd like to save it's output into variable and process some way like I did it with bash here: esxi_hwinfo.sh @ GitHub e.g.: remove some sub-strings, shorten numbers, convert one string to another etc. Is it possible to iterate over lines inside variable and get for instance the second one? Examples which I've seen work only with files ( for /f "delims=" %%1 in ('type !foo!') do ). If I use

Parse WMIC output to set returned value as a variable (windows batch)

北战南征 提交于 2021-02-13 17:36:38
问题 I have the following command: c:\wmic baseboard get Manufacturer Manufacturer ASUSTeK Computer INC. I'd like to save it's output into variable and process some way like I did it with bash here: esxi_hwinfo.sh @ GitHub e.g.: remove some sub-strings, shorten numbers, convert one string to another etc. Is it possible to iterate over lines inside variable and get for instance the second one? Examples which I've seen work only with files ( for /f "delims=" %%1 in ('type !foo!') do ). If I use

how to access a usb drive using its label and navigate with CMD

感情迁移 提交于 2021-02-11 17:51:20
问题 I would like to know if it's possible to access a usb drive using its label, for example I can navigate to the drive with PowerShell but I would like to know how to do something similar to this in CMD $usbPath = Get-WMIObject Win32_Volume | ? { $_.Label -eq 'volumelabel' } | select name ; cd $usbPath.name 回答1: The simplest, and much quicker that loading wmic , method would be to use the VOL command cmd For %G In (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)Do @Vol %G: 2>NUL|%__AppDir_

windows batch splitting file in to two based on conditions

假装没事ソ 提交于 2021-02-11 17:48:46
问题 I have a file where the starting words are any case "add" "changeprop" OR "anyother" I am trying to read such file and based on if conditions pushing that specific line to add.txt , changeprop.txt and errorrecords.txt Having hard time at the substing place as the variable is not holding the line value and i am unable to finish this job :( set "File=.\WorkFlow_Action_Script_Merged_Folder\All_WorkFlows_Merged_File.txt" SETLOCAL enabledelayedexpansion for /F "tokens=* delims=" %%a in ('Type "

Variable not recognized in else statement in a bat file

*爱你&永不变心* 提交于 2021-02-11 17:14:49
问题 I have the follow code: ECHO OFF :LOOP set c= setlocal ENABLEDELAYEDEXPANSION tasklist | find /i "calc.exe" >nul 2>&1 IF %ERRORLEVEL% == 0 ( ECHO easymeetingOnCall is running taskkill /IM calc.exe /F set c=true Timeout /T 10 goto LOOP ) ELSE ( IF "!c!" == "true" ( ECHO l'applicazione easymeetingOnCall è spenta. Timeout /T 10 goto exitLoop ) ECHO easymeetingOnCall is not running Timeout /T 5 /Nobreak GOTO LOOP ) :exitLoop My problem is that the follow condition IF "!c!" == "true" Into the else

Merging csv-files via batch

蓝咒 提交于 2021-02-11 17:11:41
问题 I need to merge a lot small csv-files from different source into separate bigger csv-files Usually I use: for /r E:\MyFolder %%d in (.) do ( copy "%%d\*.csv" "%%d\merge.txt" /B ) This works fine, but for a certain type of csv file, where a new line at the end missing where this won't work correctly. I can use : for %%x in (E:\MyFolder\case1\*.csv) do more "%%x" >>E:\MyFolder\case1\merge.txt But it won't run recursively, only for the top folder, obviously. I tried wrapping the same for loop as

Variable not recognized in else statement in a bat file

一笑奈何 提交于 2021-02-11 17:11:32
问题 I have the follow code: ECHO OFF :LOOP set c= setlocal ENABLEDELAYEDEXPANSION tasklist | find /i "calc.exe" >nul 2>&1 IF %ERRORLEVEL% == 0 ( ECHO easymeetingOnCall is running taskkill /IM calc.exe /F set c=true Timeout /T 10 goto LOOP ) ELSE ( IF "!c!" == "true" ( ECHO l'applicazione easymeetingOnCall è spenta. Timeout /T 10 goto exitLoop ) ECHO easymeetingOnCall is not running Timeout /T 5 /Nobreak GOTO LOOP ) :exitLoop My problem is that the follow condition IF "!c!" == "true" Into the else

Merging csv-files via batch

余生颓废 提交于 2021-02-11 17:11:24
问题 I need to merge a lot small csv-files from different source into separate bigger csv-files Usually I use: for /r E:\MyFolder %%d in (.) do ( copy "%%d\*.csv" "%%d\merge.txt" /B ) This works fine, but for a certain type of csv file, where a new line at the end missing where this won't work correctly. I can use : for %%x in (E:\MyFolder\case1\*.csv) do more "%%x" >>E:\MyFolder\case1\merge.txt But it won't run recursively, only for the top folder, obviously. I tried wrapping the same for loop as

Merging csv-files via batch

橙三吉。 提交于 2021-02-11 17:10:48
问题 I need to merge a lot small csv-files from different source into separate bigger csv-files Usually I use: for /r E:\MyFolder %%d in (.) do ( copy "%%d\*.csv" "%%d\merge.txt" /B ) This works fine, but for a certain type of csv file, where a new line at the end missing where this won't work correctly. I can use : for %%x in (E:\MyFolder\case1\*.csv) do more "%%x" >>E:\MyFolder\case1\merge.txt But it won't run recursively, only for the top folder, obviously. I tried wrapping the same for loop as

Merging csv-files via batch

十年热恋 提交于 2021-02-11 17:10:46
问题 I need to merge a lot small csv-files from different source into separate bigger csv-files Usually I use: for /r E:\MyFolder %%d in (.) do ( copy "%%d\*.csv" "%%d\merge.txt" /B ) This works fine, but for a certain type of csv file, where a new line at the end missing where this won't work correctly. I can use : for %%x in (E:\MyFolder\case1\*.csv) do more "%%x" >>E:\MyFolder\case1\merge.txt But it won't run recursively, only for the top folder, obviously. I tried wrapping the same for loop as