Search found 32 matches

by mataha
29 Feb 2024 16:24
Forum: DOS Batch Forum
Topic: How to put path with blanks into "for" command? Masking & quotes
Replies: 9
Views: 6754

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: 16738

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: 21315

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: 13446

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: 13446

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: 105662

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: 171745

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: 15952

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: 5272

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: 22747

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: 6049

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: 2
Views: 2077

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.
by mataha
10 Aug 2023 05:14
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10552

Re: Sanitization of carets/exclamation marks inside a macro

I'm not sure if we speak about the same :? My sample of \n is for command line macros, there it seems to be harder to build a perfect \n, my current version adds one space for each \n But your code seems to be for batch files, but there we already have a solution @echo off setlocal if "%=^%=" == "%...
by mataha
08 Aug 2023 17:31
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10552

Re: Sanitization of carets/exclamation marks inside a macro

This should work IF "" == "%$for:param=3%" echo arg3 is empty You test against command line arguments, but you should test against macro FOR-Parameters instead, there the %%3 is a safe parameter. I see. I stand corrected; I've thrown many test cases at this and couldn't find a single counterexample...
by mataha
07 Aug 2023 16:58
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10552

Re: Sanitization of carets/exclamation marks inside a macro

Yeah, looks good, but it seems that the first condition is superfluous here, because IF "" == "%$for:param=3%" if this is true then %~3 can't contain anything Not quite! Though it makes more sense with command-line arguments - if %~1 is blank (whitespace only), then the quotes (if present) will spi...