Extraction of string from a line using batch - windows

I have data in the below manner:
adb.hghgjjk.hkdhdl.Connhhhjj=hjkld\:hjkld\:thin\:hjdkdl\:3000\:abcdefg
I want to extract "abcdefg" from the above line using batch.
Above data can be changing so we need to read from the end of the line to backside and stop near : (colon) delimiter and extract it.
Any sugeestions?

Normally we do not give out code without the user at least making an attempt at trying to write some code and put some effort into researching the problem. Simple philosophy behind that is teaching a man to fish versus giving them the fish.
Give this a try.
#echo off
set "string=adb.hghgjjk.hkdhdl.Connhhhjj=hjkld:hjkld:thin:hjdkdl:3000:abcdefg"
set "first=%string::=" & set "last=%"
echo %last%
pause
If your data will never have a semicolon that you need to keep you could do this as well.
#echo off
set "string=adb.hghgjjk.hkdhdl.Connhhhjj=hjkld:hjkld:thin:hjdkdl:3000:abcdefg"
set "string=%string::=;%"
FOR %%G IN (%string%) do set "last=%%G"
echo %last%
pause
And one more example for good measure. The nice thing about batch files is alot of times there is more than one way to skin a cat.
#echo off
set "string=adb.hghgjjk.hkdhdl.Connhhhjj=hjkld:hjkld:thin:hjdkdl:3000:abcdefg"
:loop
FOR /F "tokens=1* delims=:" %%G IN ("%string%") do (
set "last=%%G"
IF NOT "%%~H"=="" (
SET "string=%%~H"
GOTO loop
)
)
echo %last%
pause

PowerShell can use regex expressions. The result is put into the R variable. If there is no match, R will be nothing.
#ECHO OFF
SET "S=adb.hghgjjk.hkdhdl.Connhhhjj=hjkld\:hjkld\:thin\:hjdkdl\:3000\:abcdefg"
SET "R="
FOR /F %%a IN ('powershell -NoLogo -NoProfile -Command ^
" '%S%' | Where-Object { $_ -match '.*:(.*$)' } | ForEach-Object { $Matches[1] } "') DO (SET "R=%%a")
ECHO R is %R%

Related

Extract list of path in a file using batch script

Here is my text file:
==================================================
Folder : D:\T\New folder
==================================================
==================================================
Folder : D:\T\Z-Ai
==================================================
==================================================
Folder : D:\T\Z-BiN
==================================================
I need to extract the paths from this file, so I have something like this:
D:\T\New folder
D:\T\Z-Ai
D:\T\Z-BiN
It seems I should use findstr TargetWord TargetFile.txt command. and Also it seems I can use regex like this: findstr /r "^[a-z][a-z]$ ^[a-z][a-z][a-z]$"
But I do not know how to loop through found targets or get the list of output. any help is really appreciated.
Based on your comment, you want to use the result to perform an xcopy task, it seems you really want something like this. Note I used example.txt as input file, and DESTINATION where you should add your destination, including the relevant xcopy switches you require:
#echo off
for /f "tokens=2*" %%i in ('type example.txt ^| findstr /i ":\\"') do xcopy "%%~j\*" DESTINATION
Alternatively we can use the findstr directly on Folder
#echo off
for /f "tokens=2*" %%i in ('type example.txt ^| findstr /i "Folder"') do xcopy "%%~j\*" DESTINATION
You can do like this :
#echo off
Title Extract list of path in a file using batch script
set "TxtList=MyList.txt"
Set "OutPutData=Output.txt"
Call :Extract "%TxtList%" "%OutPutData%"
Start "" "%OutPutData%"
Exit
::*****************************************************
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"[\w]:(\\[0-9\sA-Za-z\-]*)+"^)
echo WScript.StdOut.WriteLine Data
echo '************************************************
echo Function Extract(Data,Pattern^)
echo Dim oRE,oMatches,Match,Line
echo set oRE = New RegExp
echo oRE.IgnoreCase = True
echo oRE.Global = True
echo oRE.Pattern = Pattern
echo set oMatches = oRE.Execute(Data^)
echo If not isEmpty(oMatches^) then
echo For Each Match in oMatches
echo Line = Line ^& Trim(Match.Value^) ^& vbcrlf
echo Next
echo Extract = Line
echo End if
echo End Function
echo '************************************************
)>"%tmp%\%~n0.vbs"
cscript /nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::****************************************************
For Windows. you can use powershell.
select-string -Path c:\tmp\file.txt -Pattern '[A-Z]:(\\[0-9\ A-Za-z\-]*)+' -AllMatches | % { $_.Matches } | % { $_.Value }
In my opinion, For /F is all you need for the task. Although using Type may be useful in some situations, there's no need to use find.exe or findstr.exe for this task as you don't need to match a particular glob/pattern:
#For /F "EOL==Tokens=2*UseBackQ" %%A In ("TargetFile.txt")Do #"%__AppDir__%xcopy.exe" "%%B" "Destination\" /Options
Please note that it may be wise, if there's a chance that one or more of theses Folders do not exist, that you prepend using If Exist "%%B\". Importantly, if each of the lines containing the Folder paths, is space padded up to the end of its line, this solution will not work for you.

How to get only the first sequence of numbers in a listing using batch or powershell

What I need is the first sequence of a number in a listing:
The command:
for /f "delims=" %%a in (notas.txt) do #echo %%a
Returns:
Compra cfme NF 12345 de 123 CIA ABC
Pgto dupl. 12345 - 123 CIA ABC
Compra cfme NFS 654321-CIA CBC
Pgto NF 654321 de CIA CBC
But what I need is:
12345
12345
654321
654321
Thanks in advance
There are numerous PowerShell solution/techniques that can perform what is required.
The switch statement can be used with the -File and -Regex parameters.
switch -Regex -File notas.txt {
'\d+' { $Matches[0] }
}
You can also use the Match method from the regex class:
Get-Content notas.txt | Foreach-Object {
[regex]::Match($_,'\d+').Value
}
Both solutions rely on regex matching with \d+ matching one or more consecutive digits. Since we are doing a single match per line, the first match is the only match returned. The regex class method Matches returns multiple matches per string input.
With a Batch file using regex in vbscript you can do something like this :
Demo Here
#echo off & color 0A
Title Extract Numbers from String using Regex with vbscript
Set "InputFile=%~dp0notas.txt"
Set "OutPutFile=%~n0_OutPutFile.txt"
Call :Extract_Number "%InputFile%" CON
Call :Extract_Number "%InputFile%" "%OutPutFile%"
TimeOut /T 3 /NoBreak>nul
If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Exit
::-----------------------------------------------------------------------------------
:Extract_Number <Input> <OutPut>
(
echo WScript.StdOut.WriteLine Extract_Number(Data^)
echo Function Extract_Number(Data^)
echo Data = "%~1"
echo Data = WScript.StdIn.ReadAll
echo Set re = New RegExp
echo re.Global = True
echo re.IgnoreCase = True
echo re.Pattern = "\d{5,}"
echo For Each Match in re.Execute(Data^)
echo Number = Number ^& Match.Value ^& vbCrLF
echo Next
echo Extract_Number = Number
echo End Function
)>"%tmp%\%~n0.vbs"
cscript //nologo "%tmp%\%~n0.vbs" < "%~1" > "%~2"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
Exit /B
::----------------------------------------------------------------------------------
This first code does what your question asks, but not what your expected results show:
#echo off
:: Pass the entire line to a subroutine
for /f "delims=" %%a in (notas.txt) do call :process %%a
goto :eof
:process
:: Check if we've evaluated the entire line
if "%1"=="" (
echo No number was found in this line
goto :eof
)
:: Check if the current parameter is only numbers
:: If it is, then echo and move on to the next line
:: If not, use shift to evaluate the next parameter
echo %1|findstr /i /r "[^0-9]" >nul && shift && goto :process
echo %1
goto :eof
2 things. First, I don't know what you want to do if a number isn't found in the line. In the code above I just echo "No number was found in this line".
Second, I presumed "number" to be fully delimited with standard spaces as delimiters. Thus, the code above does NOT return 654321 from the line Compra cfme NFS 654321-CIA CBC because 654321-CIA is not a number delimited by spaces. If you want additional delimiters, then change this line above:
for /f "delims=" %%a in (notas.txt) do call :process %%a
to:
for /f "tokens=1-10 delims=-., " %%a in (notas.txt) do call :process %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j
adding whatever delimiters you want (don't forget a space before the double quote). This line is good for up to 10 entries on a given line. Going up to 26 using tokens=1-26 and %%a through %%z is pretty easy.
Finally -- if you want to pull a non-delimited number -- then that would be a completely different approach. An example would be getting 1356 from PC1356 NLA LOA; or getting 35232 from PC LI-D 35232NDA TTH.

CMD/BAT get date modified of all filenames and append to their filename

I am having trouble with this script. I'll explain below the codeblock.
#Echo off
pushd "\\server\folder"
SETLOCAL EnableDelayedExpansion
#FOR /F "TOKENS=2" %%A IN ('WHERE /T "testfiles*.*"') DO #(
set fdate123=%%A
echo !fdate123:~5,9!0!fdate123:~0,1!!fdate123:~2,2!
call StringLen !fdate123!
)
pause
:StringLen
Setlocal EnableDelayedExpansion
:: strLen String [RtnVar]
:: -- String The string to be measured, surround in quotes if it contains spaces.
:: -- RtnVar An optional variable to be used to return the string length.
Set "s=#%~1"
Set "len=0"
For %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%N,1!" neq "" (
set /a "len+=%%N"
set "s=!s:~%%N!"
)
)
Endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len%
Exit /b
What I'm trying to do it get the date modified of the file, and change the format of that date returned to YYYYMMDD. I want the date modified to be appended to the filename. I can have files from multiple days in this folder and each file may have a different date modified date.
Please do not mark this as a duplicate question, because I could not find this approach to doing this here.
I was trying to test for date string length so I can handle dates like 1/1/2019 (length of 8) vs 1/13/2019 (length of 9) vs 10/1/2019 (length of 9) vs 10/22/2019 (length of 10) then using if statements parse the date appropriately with the likes of something like !fdate123:~5,9!!fdate123:~0,1!!fdate123:~2,2! - I have not finished this yet.
I have tried getting the date with dir /T:W testfiles*.* and running a findstr but I don't understand findstr well enough to do that.
I also tried to pull it from forfiles /M BC_Services_Adjustment* /C "cmd /c echo #fdate" and moved on from that as well.
maybe somebody has a better solution, I think mine is a mess right now. Does anybody know how to get the date modified time stamp of every file in a folder, convert it a variable with YYYYMMDD format and then append it into all the files in a folder?
Note: I am not looking for powershell solutions for this question, please do not waste your time posting powershell answers.
Update #2 (5/21/19)
I tried magoo's code, I'm still needing a solution to rename the files.
#echo off
pushd "\\server\folder"
SETLOCAL EnableDelayedExpansion
FOR /F "TOKENS=2" %%A IN ('WHERE /T "*.csv"') DO (
for /f "tokens=1-3delims=/-." %%i in ("%%A") do (
set "mm=00%%i"&set "dd=00%%j"&set "yy=0000%%k"
set "fdate123=!yy:~-4!!mm:~-2!!dd:~-2!"
)
rem echo to test if date modified matches to the right filenames.
echo !fdate123! ^& %%A
rem ren "%%~nxA" "%%~nxA!fdate123!"
)
pause
I have tried with the ren "%%~nxA" "%%~nxA!fdate123!" but it's not finding the file. Probably super simple. If somebody can make magoo's code do a rename instead of just echoing the date I can award out the bounty on this question.
Be sure to specify your extentions so if your bat file is in that directory, it will not also be renamed.
#echo off
pushd "\\server\path123"
SETLOCAL EnableDelayedExpansion
FOR /r %%f IN (*.csv, *.txt) DO SET filedatetime=%%~tf & ren "%%~nf.*" "%%~nf!filedatetime:~6,4!!filedatetime:~0,2!!filedatetime:~3,2!%%~xf
FOR /F "TOKENS=2" %%A IN ('WHERE /T "testfiles*.*"') DO (
for /f "tokens=1-3delims=/-." %%i in ("%%A") do set "mm=00%%i"&set "dd=00%%j"&set "yy=0000%%k"
set "fdate123=!mm:~-2!!dd:~-2!!yy:~-4!"
echo !fdate123!
)
should allow you to construct the data according to your wishes.
The inner if assigns mm, dd and yy as appropriate, using the delimiters specified analysing %%A as a literal. Each is prefixed by an appropriate number of zeroes. The required string is then constructed using substringing selecting the last 2/4 characters of the string, so an 8-character output is obtained.
I use dd/mm/yyyy format and haven't actually tested this method, but manipulating it to your requirements should be obvious, the only issue really being how to handle yy dates as distingct from yyyy dates, if that's a concern.
I figured this out on my own, pure batch solution.
Takes date modified, appends it to any filename in a directory in YYYYMMDD format. I really was overcomplicating it, can't believe I didn't come up with this prior to setting a bounty. lol
pushd "\\server\folder"
SETLOCAL EnableDelayedExpansion
FOR /r %%f IN (*) DO SET filedatetime=%%~tf & ren "%%~nf.*" "%%~nf!filedatetime:~6,4!!filedatetime:~0,2!!filedatetime:~3,2!%%~xf"
Yes, I read that you do not want any PowerShell answers. Please be sure not to select this one as the answer. I did not waste my time writing something for you. This is for someone else who might get some benefit.
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[string]$CommandName
)
$dirlist = #('.') + ($Env:Path.Split(';'))
$extensions = #('') + ($Env:PATHEXT.Split(';'))
$results = foreach ($dir in $dirlist) {
if (($dir) -and ($dir -ne '')) {
if (Test-Path -Path $dir -ErrorAction SilentlyContinue) {
# The directory path exists.
# Check for presence of the file with any executable extension.
$dirhash = #{}
foreach ($extension in $extensions) {
Get-ChildItem -File -Path $dir -Filter "$CommandName$extension" |
ForEach-Object {
# If the file name is not already in the hash, add it to the hash
# and output it in the pipeline.
if (-not $dirhash.ContainsKey($_.Name)) {
$dirhash.Add($_.Name,1)
$_
}
}
}
}
}
}
$results | ForEach-Object {
Rename-Item -LiteralPath $_.FullName -NewName ($_.BaseName + $($_.LastWriteTime.ToString('yyyyMMdd')) + $_.Extension)
}
UPDATE:
Now that the OP's intent is known, this is a much more simple problem. Once you are confident the files will be renamed correctly, remove the -WhatIf from the Rename-Item cmdlet.
Set-Location -Path '//server/sharename'
Get-ChildItem -File -Filter 'testfiles*.*' |
ForEach-Object {
Rename-Item -LiteralPath $_.FullName -NewName ($_.BaseName + $($_.LastWriteTime.ToString('yyyyMMdd')) + $_.Extension) -WhatIf
}
I believe that the output from robocopy is in a consistent format, so I would suggest this as a possible single line batch-file option:
#PushD "\\server\folder" 2>Nul&&For /F "Tokens=1-4*Delims=/ " %%A In ('RoboCopy . $ testfiles*.* /L /NS /NJS /NJH /NDL /NC /TS')Do #Ren "%%E" "%%A%%B%%C-%%~nxE"
Alternatively, based upon your edited additional example code, this is more likely what you need:
#PushD "\\server\folder" 2>Nul&&For /F "Tokens=1-4*Delims=/ " %%A In ('RoboCopy . $ testfiles*.* /L /NS /NJS /NJH /NDL /NC /TS')Do #Ren "%%E" "testfiles%%A%%B%%C%%~xE"
If each renamed file is run through the for loop again, you may need to expand this from a single line solution to prevent it.
In both code examples, the Delimiters are /TAB                                        

Batch script extract contents between two strings

I am trying to write this Batch script to extract the two parameters from an XML file that looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<!--<var name="SqlConnection" value="data source=SERVERNAME;initialcatalog=DB_NAME;user id=JackDaniels;password=G235X" />-->
<var name="SqlConnection" value="data source=SERVERNAME;initial catalog=DB_Name;Integrated Security=SSPI" />
My objective is to extract SERVERNAME and DB_NAME from the line that is not commented out.
So far my code looks like this:
#echo off
setlocal enableextensions disabledelayedexpansion
set "connectionString="
set result=""
set "INPUT_FILE=DBConnection.config"
FOR /F "tokens=* delims=<var eol=!" %%x in (%INPUT_FILE%) DO (
ECHO %%x
)
PAUSE
I'm just not sure how to get everything right after "data source=" and "initial catalog=". Is there an easy way to do this?
The adequate way to extract this data is not via a Batch file, but with the methods suggested in a comment. However, the Batch file below perform this extraction in a relatively simple way:
#echo off
setlocal EnableDelayedExpansion
rem From the line that have "<var" followed by "value"...
for /F "delims=" %%a in ('findstr "\<var.*value" input.txt') do (
rem ... process the parts separated by space or equal sign, excepting if enclosed in quotes...
for %%b in (%%a) do (
rem ... and store the part after "value" variable
if "!var!" equ "value" set "value=%%~b"
set "var=%%~b"
)
)
rem Separate "value" string at semicolons and assign each part via SET command
for %%a in ("%value:;=" "%") do set %%a
rem Show results:
echo data source=%data source%
echo initial catalog=%initial catalog%
echo Integrated Security=%Integrated Security%
Output example:
data source=SERVERNAME
initial catalog=DB_Name
Integrated Security=SSPI
Of course, if the data format described in the code changes, the program will fail...
#ECHO Off
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "filename1=%sourcedir%\q42420941.txt"
FOR %%v IN (initial catalog data source initial_catalog data_source) DO SET "%%v="
FOR /f "delims=<>" %%z IN ('findstr /B /L /C:"\<var name" "%filename1%"') DO (
FOR %%y IN (%%z) DO (
FOR %%a IN (%%~y) DO (
SET "alive=Y"
FOR %%m IN (initial catalog data source) DO IF /i "%%a"=="%%m" SET "alive="&set %%a=Y
IF DEFINED alive (
IF DEFINED initial IF DEFINED catalog SET "initial_catalog=%%a"
IF DEFINED data IF DEFINED source SET "data_source=%%a"
)
IF DEFINED catalog IF NOT DEFINED initial SET alive=y
IF DEFINED source IF NOT DEFINED data SET alive=y
IF DEFINED alive FOR %%v IN (initial catalog data source) DO set "%%v="
)
)
)
ECHO %initial_catalog% and %data_source%
GOTO :EOF
You would need to change the setting of sourcedir to suit your circumstances.
I used a file named q42420941.txt containing your data for my testing.
first, clear out the variable-names.
next, parse each line that passes the findstr which is looking for lines that /L literally /B begin with the /c: character-sequence "< escaped by \) and take the first token delimited by > or <.
This neatly strips the awkward <> from the string and assigns the contents of the selected line to %%z
Next, use a simple for to present each token in the line to %%y.
Then with the quotes stripped off of %%y assign each token to %%a.
Search for a match against the keywords, and set the variable of the same name if found. Clear alive if a keyword is found.
If the string in %%a is not one of the keywords, then check to see whether initial and catalog are both set. If so, this is the required string, so assign it.
if catalog is found but not initial then mark as alive
If alive is still set, then we can clear the flags and wait for the start of another sequence.
OK - it has its faults. It won't detect initial_catalog/data_source if either is one of the four keywords (unlikely) and it assumes that the wanted data is the token following the two keywords - the = becomes a separator in the for list.
Since many of you suggested that Batch is not an adequate way of doing this, I decided to play around with PowerShell, and was able to accomplish what I wanted with just a few lines, and some Regex!
$configPath = $PSScriptRoot + "DBConnection.config"
[xml]$XmlDocument = Get-Content -Path $configPath
$dataSource = $XmlDocument.var.Attributes[1].Value.ToString() # Extract the uncommented line, and the second attribute "value"
$serverName = ($dataSource -split 'data source=([^;]*);')[1]
$db_name = ($dataSource -split 'initial catalog=([^;]*);')[1]
$user_id = ($dataSource -split 'id=([^;]*);')[1]
$user_pass = ($dataSource -split 'password=([^;]*)')[1]

DOSKEY recall alias

Is it possible to recall an alias with DOSKEY?
Simple example .. I wish to do something like that:
DOSKEY a=someCommand
DOSKEY b=someOtherCommand
DOSKEY c=andAThirdCommand
:: How to do this? -> DOSKEY all=a+b+c
I already know that I can do this by writing this:
DOSKEY all=someCommand ^& someOtherCommand ^& andAThirdCommand
but in the sense of reusing stuff I'd like to reuse my defined aliases from above.
Is it possible like I desire?
Thanks!
PS: Saw this here, but it's not a satisfying answer. It seems that it won't work though. :(
Good question, hard to answer... However, I can suggest a workaround with a simple batch script(s).
Suppose we have defined doskey a=commandA and doskey a=commandB and doskey c=commandC macros.
Static approach: let's name our script e.g. dem (define macro) and place it somewhere in your path. Then dem acb a c b should define a new macro acb (ready to further use) as follows: doskey acb=commandA $T commandC $T commandB. That script could be established by a little adaptation from the script dsk provided (hint: instead of launching a macro text, constitute the text for new macro, but be aware of another escaping).
Dynamic approach: let's name our script e.g. dsk (doskey) and place it somewhere in your path. Then dsk a b c should call macros a, b and c in that sequence. Number of parameters (macro names) passed to script is not limited. The script works well with very simply defined macros, but
allows % percent sign use like in doskey a=echo %variable% macro and/or even for loops like in doskey a=for /F "tokens=*" %G in ('dir /b /s *.txt') do #echo %G;
allows $T concatenated commands in a macro (equivalent to & in a batch file) like doskey a=dir $T set; done by replacing $T with & (in rare cases does not suffice, then need to split and perform commands separately).
Known issues and/or restrictions (impossible to resolve without knowing more about real structure of macros used); the dsk script
a for loop could bring problems with %%parameter variable; vetoed to use in a macro: %%{ (outer loop) and %%? %%# (inner loop)
does not make allowance for piping or redirecting like doskey a=dir ^> somefile;
does not make allowance for ^& concatenated commands in a macro (but allows doskey intrinsic $T concatenation);
does not make allowance for launching batch .bat or .cmd scripts (needs call %xitem% instead of %xitem% in the :doItem procedure (cca 50th line);
if a macro name isn't found, it's simply overskipped...
The script dsk is as follows:
:: dsk.bat
#ECHO OFF >NUL
#SETLOCAL enableextensions enabledelayedexpansion
set "CheckOnly=0"
set "DoneList="
set "ToDoList="
set "xitem=x"
for %%{ in (%*) do (
set "_G_found=0"
echo.
for /F "tokens=1* delims==" %%? in ('doskey /macros') do (
if /i "%%{"=="%%?" (
for /F "tokens=*" %%_ in ("%%#") do set "item=%%_"
if /i "!item:~0,3!"=="for" set "item=!item:%%=%%%%!"
if "%CheckOnly%"=="1" (
echo : to do: '!item!'
) else (
echo : To Do: '!item!'
call :doItem !item!
)
set "DoneList=!DoneList! +%%{"
set "_G_found=1"
)
)
if "!_G_found!"=="0" (
set "DoneList=!DoneList! -%%{"
echo : macro: [%%{] ^(not found^)
if "!ToDoList!"=="" set "ToDoList=!ToDoList!, [%%{]"
if "!ToDoList!"=="!ToDoList:[%%{]=!" set "ToDoList=!ToDoList!, [%%{]"
)
)
echo.
echo :
echo : trailing progress report
echo :
if "%ToDoList%"=="" (
echo : all found: %DoneList:~1%
) else (
echo : +found, -not found: %DoneList:~1%
echo : %ToDoList:~2% not found in macro name list
)
echo : end of batch %~f0
echo :
:endlocal
#ENDLOCAL
#goto :eof
:doItem
set "xitem=%*"
set "xitem=%xitem:$T=&%"
%xitem%
#goto :eof
With next scenario:
d:\bat>doskey /macros
y=for /F "tokens=*" %g in ('dir /b rand.bat') do #echo %g
x=dir /B /AD $T dir /B /AD "D:\Remote\bat\COCL\bu bu bu" $T set y
a=echo CheckOnly=%CheckOnly%
b=rand.bat
and dsk y b a x n call gives next output:
d:\bat>dsk y b a x n
: To Do: 'for /F "tokens=*" %%g in ('dir /b rand.bat') do #echo %%g'
rand.bat
: To Do: 'rand.bat'
The system cannot find the batch label specified - doItem
: To Do: 'echo CheckOnly=%CheckOnly%'
CheckOnly=0
: To Do: 'dir /B /AD $T dir /B /AD "D:\Remote\bat\COCL\bu bu bu" $T set y'
files
a.dot 1.dot 2.dot 3
Environment variable y not defined
: macro: [n] (not found)
:
: trailing progress report
:
: +found, -not found: +y +b +a +x -n
: [n] not found in macro name list
: end of batch d:\bat\dsk.bat
:
d:\bat>
The script is rather verbose for debugging purposes (and variable CheckOnly as well, with values 1= only echo commands, 0= echo and execute commands in a macro).

Resources