Search found 35 matches

by mataha
06 Aug 2024 16:34
Forum: DOS Batch Forum
Topic: Scope termination and echo state
Replies: 1
Views: 17765

Scope termination and echo state

I've encountered a behaviour I do not quite understand. C:\Users\user> A.cmd Waiting for 1 seconds, press a key to continue ... A.cmd: @echo off (goto) 2>nul || B.cmd B.cmd @echo off (goto) 2>nul || "%SystemRoot%\system32\timeout.exe" /t 1 Why is echo state not restored afterwards? Does using (goto)...
by mataha
06 Aug 2024 15:58
Forum: DOS Batch Forum
Topic: Looks like dostips is extensively on AI training?
Replies: 1
Views: 13513

Re: Looks like dostips is extensively on AI training?

My thoughts exactly; 2745 (as of now) views is more than this board might get in a week.

Here's hoping that, one day, AI can actually help writing Batch...
by mataha
06 Aug 2024 15:54
Forum: DOS Batch Forum
Topic: How to put path with blanks into "for" command? Masking & quotes
Replies: 10
Views: 31709

Re: How to put path with blanks into "for" command? Masking & quotes

Escaping the quotes shouldn't be necessary: for /f delims^= %%g in ('""D:\some\path\with blanks inside\myprog.exe" -p "......" %1"') do set "....." We have a discussion about it here on DosTips. I will see if I can dig up that thread. I've answered myself - those escaped quotes lose their semantics...
by mataha
29 Feb 2024 16:24
Forum: DOS Batch Forum
Topic: How to put path with blanks into "for" command? Masking & quotes
Replies: 10
Views: 31709

Re: How to put path with blanks into "for" command? Masking & quotes

Escaping the quotes shouldn't be necessary:

Code: Select all

for /f delims^= %%g in ('""D:\some\path\with blanks inside\myprog.exe" -p "......" %1"') do set "....."
by mataha
22 Nov 2023 07:55
Forum: DOS Batch Forum
Topic: Problem passing parameters by ref in for /R
Replies: 3
Views: 20377

Re: Problem passing parameters by ref in for /R

Regarding for /r : there is no tokenization involved as far as the first argument (directory) is concerned; if there are leading and trailing quotes by the time cmd has finished parsing the line, they are stripped. That's it. If you want to use a variable there, it has to be expanded eagerly (i.e. v...
by mataha
12 Nov 2023 17:15
Forum: DOS Batch Forum
Topic: ECHOing to a file without a trailing space
Replies: 6
Views: 25474

Re: ECHOing to a file without a trailing space

Should be resilient enough:

Code: Select all

@setlocal DisableDelayedExpansion
@set field1=a
@set field2=(a
@set field3=2
@set field4=34564119
@setlocal EnableDelayedExpansion

@for /f delims^= %%s in ("(!field1!;!field2!;!field3!;!field4!)") do @(echo(%%s) >"file4.tmp"
by mataha
25 Oct 2023 11:47
Forum: DOS Batch Forum
Topic: Adding a new DosKey command
Replies: 4
Views: 15958

Re: Adding a new DosKey command

Does this answer your question? Obviously you have to run it from an elevated command prompt. > doskey lv = ((echo Disk Volume) ^& (echo -----------) ^& (echo list volume) ^| diskpart ^| findstr "Volume ###" ^| findstr /v /c:"Volume ###") > lv Disk Volume ----------- Volume 0 D DVD-ROM 0 B No Media ...
by mataha
23 Oct 2023 14:29
Forum: DOS Batch Forum
Topic: Adding a new DosKey command
Replies: 4
Views: 15958

Re: Adding a new DosKey command

Try:

Code: Select all

doskey lv=echo(^& echo list volume $B diskpart
by mataha
12 Oct 2023 16:17
Forum: DOS Batch Forum
Topic: Variable inside an IF not showing correctly
Replies: 18
Views: 115535

Re: Variable inside an IF not showing correctly

Docfxit wrote:
12 Oct 2023 15:47
Why doesn't it GOTO FileCopied with RoboCopy like it does with XCopy?
See robocopy exit codes.
by mataha
07 Oct 2023 19:26
Forum: DOS Batch Forum
Topic: Rules for how CMD.EXE parses numbers
Replies: 41
Views: 189398

Re: Rules for how CMD.EXE parses numbers

One more forgotten case .. IF [NOT] ERRORLEVEL N .And works surprisingly correct . It should detect if the current errorlevel is bigger or equals to the given number.Does not accept non-numerical strings. (...) (not the fastest way to?) check if a string is a number: (if errorlevel %number% break )...
by mataha
03 Oct 2023 19:03
Forum: DOS Batch Forum
Topic: Is there a way to subtract 2 days from this batch file?
Replies: 5
Views: 19818

Re: Is there a way to subtract 2 days from this batch file?

Though incomplete, you might want to use $dayadd macro from here like so:

Code: Select all

set /a "date.day=2, date.month=3, date.year=2000"
%$putout% "%date.day%.%date.month%.%date.year%"
%$dayadd% date -2
%$putout% "%date.day%.%date.month%.%date.year%"

Code: Select all

2.3.2000
29.2.2000
by mataha
13 Sep 2023 06:54
Forum: DOS Batch Forum
Topic: [SOLVED] grep + HTML angle brackets?
Replies: 3
Views: 8926

Re: grep + HTML angle brackets?

May I recommend ripgrep instead? > rg --pcre2 --text --only-matching --no-filename "<html>" index.html 1:<html> > rg -PoIa "<html>" index.html 1:<html> Although cmd should have no problems accepting angle brackets as long as they're within quotes. The following is equivalent: > rg --pcre2 --text --o...
by mataha
29 Aug 2023 12:16
Forum: DOS Batch Forum
Topic: Safer way to parse curl output?
Replies: 4
Views: 25937

Re: Safer way to parse curl output?

Not bulletproof, but should get the job done: setlocal EnableDelayedExpansion (set ^"\n=^ ) & for /f delims^=^ eol^= %%l in ("curl (...)") do ( set "line=%%l" set "line=!line:~1,-1!" for %%n in ("!\n!") do for /f "tokens=1,* delims=:" %%u in ("!line:,=%%~n!") do ( if "%%~u" equ "device_code" ( set "...
by mataha
27 Aug 2023 08:18
Forum: DOS Batch Forum
Topic: why does del /q "" work like del /q *.* and ruin me
Replies: 3
Views: 9759

Re: why does del /q "" work like del /q *.* and ruin me

I had a quick look at the available source code, but didn't see anything at the first glance: int eDelete(struct cmdnode *n) { return(LastRetCode = DelWork(n->argptr)); } int DelWork(TCHAR *pszCmdLine) { DRP drpCur = {0}; TCHAR szCurDrv[MAX_PATH + 2]; ULONG OldDCount; STATUS rc; OldDCount = DCount; ...
by mataha
10 Aug 2023 16:30
Forum: DOS Batch Forum
Topic: Trouble with ROBOCOPY - copy files to destination that don't already exist
Replies: 3
Views: 16234

Re: Trouble with ROBOCOPY - copy files to destination that don't already exist

Take a look at /im; /mir might be relevant for your use-case as well.