Search found 243 matches

by T3RRY
11 Feb 2024 13:44
Forum: DOS Batch Forum
Topic: Macro for Dummies
Replies: 16
Views: 6492

Re: Macro for Dummies

for /f %%! in ("! ^! ^^^!") Why is there a '^' before the second '!' in the %%! definition above? I've run lots of tests without that '^', and never had any problem with that: for /f %%! in ("! ! ^^^!") because the behavior differs marginally. ultimately though, ts a preference to convery the purpo...
by T3RRY
10 Feb 2024 23:12
Forum: DOS Batch Forum
Topic: Macro for Dummies
Replies: 16
Views: 6492

Re: Macro for Dummies

Steffen has answered well here the basics, with one minor ommission The newline variable used for multiline definitions only works within parenthesised codeblocks A simple example @Echo off (Set $\n=^^^ %= DO NOT MODIFY $\n Newline variable definition =%) Set example1=Echo Hello World 1 %$\n% Pause ...
by T3RRY
10 Feb 2024 00:27
Forum: DOS Batch Forum
Topic: Macro for Dummies
Replies: 16
Views: 6492

Macro for Dummies

As requested by @miskox at https://www.dostips.com/forum/viewtopic.php?f=3&t=10983#p69429 As remarked within the code, this template is intended to make it easy to create macro's that take arguments The template does nothing with the arguments other than splitting them and returning them in an array...
by T3RRY
18 Jan 2024 16:00
Forum: DOS Batch Forum
Topic: How to copy a txt file into multiple txt files in a destination folder
Replies: 3
Views: 2204

Re: How to copy a txt file into multiple txt files in a destination folder

Hello All, I tried copying the content of a txt file into multiple txt files in a destination folder but not getting the expected result. I've tried : "Copy my file.txt floder\×.txt" but it's not updating all the txt files. Can someone help me out? why would you expect it to? Copy cannot append to ...
by T3RRY
18 Jan 2024 12:39
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 75
Views: 94583

Re: infinite loop with break condition

Use substring substitution to replace the break variable for each additional while IE \b1 for the first break, \b2 for the second and so on I understand the advantage of generating unique break variable names for each loop. But I don't understand which substring substitution would allow to do that....
by T3RRY
18 Jan 2024 08:31
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 75
Views: 94583

Re: infinite loop with break condition

(By analogy with WEND, I renamed yesterday's ENDREP as REND.) Particularly in the situation of defining multiple Whiles into a macro, there's a simple alternative to WEND Use substring substitution to replace the break variable for each additional while IE \b1 for the first break, \b2 for the secon...
by T3RRY
18 Jan 2024 07:55
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7629

Re: Faster batch macros

Arthur Clarke once said that perfection was reached, not when you can't add anything anymore to your system, but when you can't remove anything from it without it stopping functionning. I think you may have reached perfection here. Couldn't agree more. Not only is it the most concise, it's the most...
by T3RRY
12 Jan 2024 00:00
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7629

Re: Faster batch macros

This is cool. Thought of a fun way to do it, though haven't tested it inside a macro or anything. This way the 2 FOR loops aren't needed, though the string is much longer. @ECHO ON SETLOCAL ENABLEDELAYEDEXPANSION SET "v=1" FOR /F "tokens=2-7" %%1 in ("!! SET REM ENABLEDELAYEDEXPANSION END REM LOCAL...
by T3RRY
11 Jan 2024 19:57
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7629

Re: Faster batch macros

I didn't understand a thing Jeb wrote. I tried to learn how to make/use macros. No luck. A 'macro for dummies' should be posted by someone who can do it. Saso the short of it: using setlocal / endlocal regardless of environment state adds a performance cost that can be minimised by modifying those ...
by T3RRY
10 Jan 2024 03:39
Forum: DOS Batch Forum
Topic: How to replace the script name %~n0 with a string of "-" characters of length %~n0?
Replies: 1
Views: 2169

Re: How to replace the script name %~n0 with a string of "-" characters of length %~n0?

Hi How to replace the script name %~n0 with a string of "-" characters of length %~n0? ex. %~n0 = Test.bat How do I change "Test.bat" to the string "---------" ? Test.bat -------- Isn't this essentially the same question you asked at https://www.dostips.com/forum/viewtopic.php?f=3&t=10962&sid=a5ee3...
by T3RRY
09 Jan 2024 21:36
Forum: DOS Batch Forum
Topic: Faster batch macros
Replies: 17
Views: 7629

Re: Faster batch macros

Nice work as always Jeb. Had to make a couple of changes to get it working in conjunction with the trick of For /f %%! in ("! ! ^^^!") Do for environment independent definition as well as execution. The above resulted in an expansion error occuring within the for set of the %%E loop when defined in ...
by T3RRY
16 Jun 2023 01:57
Forum: DOS Batch Forum
Topic: count characters of a input string in batch file
Replies: 4
Views: 2045

Re: count characters of a input string in batch file

Aacini wrote:
16 Jun 2023 00:04
There are a lot of different ways to solve this problem. This is another (simpler, I think) method:

Antonio
Provided of course that the input string doesn't start with leading `=` or whitespace.
by T3RRY
15 Jun 2023 21:01
Forum: DOS Batch Forum
Topic: count characters of a input string in batch file
Replies: 4
Views: 2045

Re: count characters of a input string in batch file

Hi, I want to write a batch script that can count uppercase and lowercase characaters and digits and special characaters of input string for example if I enter this: 7f(92_/%67G46sMg_<2kkDgit4_+^H!aYCe=_-wQW4S=taMnGBDQLGx(F>^>(SFob@eUxFH0-2#yAJK/i!Q=BiWJ@z/4KKwNF#T= it will show me this: upper : 34...
by T3RRY
04 Jun 2023 09:36
Forum: DOS Batch Forum
Topic: Combinations of N numbers in sets of K with R repeated elements
Replies: 9
Views: 2961

Re: Combinations of N numbers in sets of K with R repeated elements

This was indeed an interesting problem. here was my own solution, a very brute force approach. Runs reasonably quick on my machine ~ 30 seconds for 100 lines, but mines a reasonably new and not so slow machine. Speed drops off exponentially as the total list size increases EDIT: Testing for the 300 ...
by T3RRY
03 May 2023 11:10
Forum: DOS Batch Forum
Topic: create macro: Let's create a small handout with reports .
Replies: 17
Views: 4564

Re: create macro: Let's create a small handout with reports .

Hi Antonio, Yes you are right it's very theoretical and impractical, but' an extract of the code. Now I will try to explain myself better. This is the code that I have to optimize summarized to the bone. And the problem I face is writing macros. I'm no expert in writing code that needs to be treate...