Search found 1659 matches

by Aacini
05 Aug 2020 10:34
Forum: DOS Batch Forum
Topic: Performance Issues with Code
Replies: 18
Views: 244

Re: Performance Issues with Code

Inspired by @Aacini's solution, some pseudo-code as I dont have the time and experience to convert this to proper code: Instead of month n=1..12, set month= 2^^n -1 (1.. 4095) set /a min=4095, max=0 For loop: set /a min="min & month", max="max | month" After the for-loop, convert 2^^n - 1 back to n...
by Aacini
04 Aug 2020 14:41
Forum: DOS Batch Forum
Topic: Performance Issues with Code
Replies: 18
Views: 244

Re: Performance Issues with Code

Perhaps this would run a little faster... @echo off setlocal EnableDelayedExpansion rem Empty environment ( for /F "delims==" %%a in ('set') do set "%%a=" set "ComSpec=%ComSpec%" ) set /A "i=0, j=100" for %%a in (January February March April May June July August September October November December) ...
by Aacini
02 Aug 2020 12:36
Forum: DOS Batch Forum
Topic: FOR variable %%A in macro definition gets overridden when script is called by other script within FOR loop
Replies: 15
Views: 259

Re: FOR variable %%A in macro definition gets overridden when script is called by other script within FOR loop

This "strange" behavior of FOR parameters was previously discussed here (and in a nested link there): "The "global within a FOR context" design can lead to some nasty surprises. You might write a subroutine with a FOR loop that echos text with a percent literal. The routine works perfectly fine. The...
by Aacini
31 Jul 2020 23:17
Forum: DOS Batch Forum
Topic: Get line with highest numerical string
Replies: 12
Views: 2425

Re: Get line with highest numerical string

I think this do the trick: @echo off setlocal EnableDelayedExpansion set lastNum=0 for /F "delims=" %%a in ('findstr "outbox/logs/.*[0-9]\.log" test.txt') do ( set "a=%%~Na" for %%b in ("!a:_=.!") do set "num=%%~Xb" if !num:~1! gtr !lastNum! set "lastNum=!num:~1!" & set "lastLine=%%a" ) echo %lastLi...
by Aacini
31 Jul 2020 02:50
Forum: DOS Batch Forum
Topic: Only accept a numeric number.
Replies: 18
Views: 364

Re: Only accept a numeric number.

IMHO, "only accept a number between 1 and 12" is something entirely different to "accept any string and check if it is a number between 1 and 12. If not, repeat the input" . The code below do the first thing: @echo off setlocal EnableDelayedExpansion rem Initialize variables for /F %%a in ('copy /Z ...
by Aacini
31 Jul 2020 02:08
Forum: DOS Batch Forum
Topic: JREPL: Cutting of a string after the n-th occurrence of specific character?
Replies: 17
Views: 602

Re: JREPL: Cutting of a string after the n-th occurrence of specific character?

The irrelevant string preceding the directory path is cancelled if you use the /B switch in DIR command, as I did in my first answer. Didn't you saw it? Mmmm... I am afraid I don't understand what exactly the problem is... However, if you have these directories in the disk: C:\Users\Guy C:\Users\Guy...
by Aacini
29 Jul 2020 11:36
Forum: DOS Batch Forum
Topic: JREPL: Cutting of a string after the n-th occurrence of specific character?
Replies: 17
Views: 602

Re: JREPL: Cutting of a string after the n-th occurrence of specific character?

This is the fastest way for variable "recursion depth": @echo off setlocal EnableDelayedExpansion rem Assemble output masks for variable directory nesting level set "accum=%%a" set "letter=bcdefghijklmnopqrstuvwxyz" for /L %%i in (1,1,25) do ( set "tok[%%i]=%%!letter:~0,1!" set "accum=!accum!\%%!let...
by Aacini
28 Jul 2020 21:23
Forum: DOS Batch Forum
Topic: JREPL: Cutting of a string after the n-th occurrence of specific character?
Replies: 17
Views: 602

Re: JREPL: Cutting of a string after the n-th occurrence of specific character?

Mmmm... I am afraid I don't understand what exactly the problem is... However, if you have these directories in the disk: C:\Users\Guy C:\Users\Guy\Desktop C:\Users\Guy\Desktop\Unnecessarily\Deep ... then this code: for /F "tokens=1-4 delims=\" %%a in ('dir /S /B') do ( if "%%d" neq "" echo %%a\%%b\...
by Aacini
28 Jul 2020 15:58
Forum: DOS Batch Forum
Topic: Dynamically load array with variable value
Replies: 3
Views: 201

Re: Dynamically load array with variable value

In your first post you clearly specified to split the PARAM string in array elements , but later you don't even use such array elements! :shock: In your first post it is assumed to extract the values of the variables (productname, productid), but no, you don't use such variables... :? Ok. Here it is...
by Aacini
28 Jul 2020 09:04
Forum: DOS Batch Forum
Topic: Dynamically load array with variable value
Replies: 3
Views: 201

Re: Dynamically load array with variable value

Your question is confusing. There are several points that are not clear enough... However, I think this code does what you requested: @echo off setlocal EnableDelayedExpansion SET "PARAM=productname=%%a&productid=%%b empid=%%a&empname=%%b&empad=%%c" rem Parse "PARAM" and load space-delimited values ...
by Aacini
28 Jul 2020 07:35
Forum: DOS Batch Forum
Topic: FOR /F Text Reading: Retain Empty Lines & Dynamic Skip?
Replies: 2
Views: 214

Re: FOR /F Text Reading: Retain Empty Lines & Dynamic Skip?

Well, the way to solve your problems in the way you want is to rewrite cmd.exe in the part that implements the FOR command! :shock: :lol: However, if you still want a solution, then try this: Implement a read/no_read flag. Set it when you want to skip lines and reset it to continue reading lines. Us...
by Aacini
28 Jul 2020 07:22
Forum: DOS Batch Forum
Topic: JREPL: Cutting of a string after the n-th occurrence of specific character?
Replies: 17
Views: 602

Re: JREPL: Cutting of a string after the n-th occurrence of specific character?

vin97 wrote:
27 Jul 2020 11:24

. . . . .

Still intersted in whether or not things could be sped up by using something other than JREPL for these tasks.
Perhaps if you post some examples of the input lines and the desired output for them, we could try to write a solution...

Antonio
by Aacini
16 Jul 2020 10:30
Forum: DOS Batch Forum
Topic: loop without for to read lines of a file
Replies: 15
Views: 855

Re: loop without for to read lines of a file

Simple question: what is the purpose of using several handles in your code? Messing up all? Handles are used to read files. You need one handle for each file. Are your reading more than one file? If not, what is the purpose of using more than one handle? Do you want to solve your reading file proble...
by Aacini
16 Jul 2020 06:18
Forum: DOS Batch Forum
Topic: loop without for to read lines of a file
Replies: 15
Views: 855

Re: loop without for to read lines of a file

Hi. I wrote this working example based on your original code: @echo off setlocal EnableDelayedExpansion set "ndx=0" call :ReadFile < variables.txt echo After read: for /L %%i in (1,1,%ndx%) do echo !a[%%i]! goto :EOF :ReadFile set "val=" set /P "val=" if "%val%" == "" goto exitLoop set /A ndx+=1 set...
by Aacini
09 Jul 2020 05:25
Forum: DOS Batch Forum
Topic: Code logic problem - transform lines to columns
Replies: 4
Views: 527

Re: Code logic problem - transform lines to columns

@echo off setlocal EnableDelayedExpansion set "TAB= " for %%f in (*.txt) do ( set "head=" (for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "%%f"') do ( if not defined head ( set "head=%%b" ) else if "%%b" neq "" ( echo !head!!TAB!%%b ) else ( echo/ set "head=" ) )) > "%%~Nf.out" ) Antonio