Search found 1041 matches

by jeb
18 Feb 2024 03:06
Forum: DOS Batch Forum
Topic: Automating the generation of macros usable within other macros
Replies: 4
Views: 709

Re: Automating the generation of macros usable within other macros

Hi jfl, One side issue I'm still investigating is a good way to define a %%variable that generates a %. Using a %%p variable is easy, but this might interfere with a user-defined %%p variable. I tried using the same syntax with a caret, as for the other tricky characters: for %%^% in (1 2) do ... Th...
by jeb
12 Feb 2024 10:29
Forum: DOS Batch Forum
Topic: Macro for Dummies
Replies: 16
Views: 6498

Re: Macro for Dummies

@jfl Nice efforts :D Note that with expansion enabled, and in the absence of a ! in the command, both the FOR! and FOR!! macros generate two ^^ for each %%^^. This is unavoidable. But the solution for this problem should be obvious 8) From the Batch Library/libBase.cmd REM *** Creating %%! and %%^ f...
by jeb
11 Feb 2024 15:11
Forum: DOS Batch Forum
Topic: Macro for Dummies
Replies: 16
Views: 6498

Re: Macro for Dummies

because the behavior differs marginally. ultimately though, ts a preference to convery the purpose Your example only shows the fact that a variable can be expanded, when the name is complete @echo off Set a1 =-ONE- Set "a1 ^=-TWO-" Setlocal EnableDelayedExpansion for /f %%! in ("!a1 ! ^^^!") Do Ech...
by jeb
22 Jan 2024 03:29
Forum: DOS Batch Forum
Topic: 3D Cube Orthographic Projection
Replies: 3
Views: 2268

Re: 3D Cube Orthographic Projection

Hi IcarusLives, nice picture, but currently the code on my WIN10 only produces: Fehlender Operand Fehlender Operand Fehlender Operand [2J[38;5;1m[0;1H´┐¢[0m[38;5;6m[0;1H´┐¢[0m[38;5;11m[0;1H´┐¢[0m[38;5;2m[0;1H´┐¢[0m[38;5;7m[0 ;1H´┐¢[0m[38;5;12m[0;1H´┐¢[0m[38;5;3m[0;1H´┐¢[0m[38;5;8m[0;1H´┐¢[0m[38;5;13...
by jeb
19 Jan 2024 07:09
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7639

Re: Faster batch macros

Uhh that's something that can drive you mad. You need to glue it to the next command because it would be treated as a separate command otherwise. Even an empty string or a space is parsed like that. I can't make my brain remember the order and details of script parsing. The parser splits in phase 2...
by jeb
19 Jan 2024 06:57
Forum: DOS Batch Forum
Topic: NOP+nested code.
Replies: 25
Views: 17649

Re: NOP+nested code.

I build a test script to measure the time and check if the constructs would work with FOR-meta-variable expansions. "rem=" or "rem," are still the winner, but even "if %%? == 0" and 'FOR /F %%? in ("%%~?") DO ' are still fast enough Neither "echo>nul" nor "rem^ " can't be used as switchable NOP. Bec...
by jeb
16 Jan 2024 07:08
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7639

Re: Faster batch macros

@jfl Thanks, your short version of the @Lowsun FOR/F-loop was exactly what I had in mind. But your tests with `if [!!]==[]` has to be failed, because the expression works only at the start detection, but in the end it fails, because then delayed expansion is always enabled and you can't decide with ...
by jeb
16 Jan 2024 05:51
Forum: DOS Batch Forum
Topic: FOR /R puzzler? (wildcarded folders only, e.g. A*)
Replies: 5
Views: 3349

Re: FOR /R puzzler? (wildcarded folders only, e.g. A*)

I observed something interesting; with one master .bat containing the for, and that for executing do foo.bat "%%G" (the FINDSTR resides in foo.bat), and having ECHO OFF on each .bat, it was still very noisy. Changing that to do CALL foo.bat "%%G" silenced it. Normally I only remember to insert CALL...
by jeb
05 Jan 2024 14:29
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7639

Faster batch macros

Hi, while I try to build a small batch list selection component for a customer, I stumbled about the horrible, poor performance of batch functions on network drives. My code used the standard :strlen function 180 times and it takes some seconds. I decided to use a strlen macro, it's faster, but stil...
by jeb
01 Jan 2024 14:41
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 75
Views: 94639

Re: infinite loop with break condition

Hi Sponge Belly, it's a really nice idea and so simple. And I like the combineable hex values to the total counter. But you inspired me to think about another problem, I want to use the infinite loop in macros where goto can't be used. It can be solved either with an if defined expression or even si...
by jeb
28 Dec 2023 05:54
Forum: DOS Batch Forum
Topic: Save command result in a variable
Replies: 3
Views: 3119

Re: Save command result in a variable

It fails because percent expansion is evaluated before a code block is executed. Therefore you need delayed expansion here. setlocal EnableDelayedExpansion set "output=" for /f "delims=" %%a in ( 'dism /Online /Get-Capabilities ^| findstr "OpenSSH.Server"' ) do ( set "output=!output!%%a" ) echo !out...
by jeb
27 Dec 2023 05:08
Forum: DOS Batch Forum
Topic: Save command result in a variable
Replies: 3
Views: 3119

Re: Save command result in a variable

Hi vaschthestampede, the "normal" way is to use the FOR /F command. for /F "delims=" %%A in ('VER') do set "output=%%A" echo output is '%output%' But the part `set output=%%A` is called for each line of the output, therefore only the last line is stored. In your case you should get only one line by ...
by jeb
25 Dec 2023 10:14
Forum: DOS Batch Forum
Topic: custom console window banner
Replies: 4
Views: 3937

Re: custom console window banner

Hi lazna. Seems even multiline prompt break scripts too :-/ So it looks this concept is wrong from scratch. The obvious way: Don't break scripts by not outputting anything. Output your banner only when you are not in a script. Sounds simple, but then you have to solve the problem of the decision who...
by jeb
12 Dec 2023 07:15
Forum: DOS Batch Forum
Topic: Parsing exclamation marks in filenames of %%i
Replies: 1
Views: 3911

Re: Parsing exclamation marks in filenames of %%i

Hi RuinedElf , your problem is, that expansion of FOR-variables is only safe when DelayedExpansion is disabled. But working with variables is only safe when DelayedExpansion is enabled. You can solve this by toggling delayed expansion. REM Loop through all MP4 files in the input directory and its su...
by jeb
13 Nov 2023 04:59
Forum: DOS Batch Forum
Topic: ECHOing to a file without a trailing space
Replies: 6
Views: 15278

Re: ECHOing to a file without a trailing space

With DelayedExpansion it's safe with all character, but then you don't need the FOR /F

Code: Select all

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

(echo(!field1!;!field2!;!field3!;!field4!) >"file4.tmp"