Search found 31 matches

by OJBakker
02 Aug 2020 14:12
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: 212

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

The problem is in the for''s. You don't want the %%A used when you define your macro but only when you use the macro. The cause of your problem is the for %%g loop in caller.cmd. This for loop makes the %%A available in the do command block. In your example code you don't need this loop. replace for...
by OJBakker
01 Aug 2020 13:10
Forum: DOS Batch Forum
Topic: Categorize file extension in .txt output
Replies: 3
Views: 92

Re: Categorize file extension in .txt output

unttested, but this should be close to what you are trying to achieve.

Code: Select all

if exist Files.txt del Files.txt
for %%A in (asi ini cs asi) do dir /O:D /T:W  *.%%A >> Files.txt
for %%A in (asi ini cs asi) do dir /O:D /T:W  /s *.%%A >> Files.txt
by OJBakker
12 Jun 2020 13:52
Forum: DOS Batch Forum
Topic: Batch hex edit offset from filename
Replies: 8
Views: 962

Re: Batch hex edit offset from filename

For work I regularly end up with a bunch of hex files with the extension .hex, but I can have anywhere from 5 all the way up to in the hundreds. Most of the time the files will be the same, but require me to open them and edit a select set of values before saving and closing. Right now I am using H...
by OJBakker
07 Apr 2020 01:45
Forum: DOS Batch Forum
Topic: Batch - Browse directory not work
Replies: 3
Views: 1057

Re: Batch - Browse directory not work

Your subroutine :treatment is missing the 'end subroutine' command.
This causes processing of :treatment to continue with the command in :end, so processing stops with the''exit %CodeRetour%' command.

Add 'exit/B' or 'goto :eof' at the end of the subroutine to correct this.
by OJBakker
28 Feb 2020 06:03
Forum: DOS Batch Forum
Topic: How to replace extension of a filename stored in variable?
Replies: 6
Views: 3965

Re: How to replace extension of a filename stored in variable?

The 'set "file2=%%~i"' does work, but is done inside the for-commandblock enclosed in ()
Use delayed expansion to echo and use the uptodate value of %file2%.
Change %file2% in !file2! and %newfile2% in !newfile2! and your code will work as expected.
by OJBakker
07 Dec 2011 15:14
Forum: DOS Batch Forum
Topic: Searching Double quote using FINDSTR inside FOR
Replies: 4
Views: 3077

Re: Searching Double quote using FINDSTR inside FOR

or with less carets but more ""

Code: Select all

FOR /f "tokens=1 delims=:" %a in ('"FINDSTR /n /c:"^"" s.txt"') do echo %a
by OJBakker
03 Dec 2011 19:12
Forum: DOS Batch Forum
Topic: Help me escape special characters used in a %VAR% variable
Replies: 10
Views: 3429

Re: Help me escape special characters used in a %VAR% variab

I am not entirely sure but these might work:
SET COMMAND=('find /n "" < %2')
SET COMMAND=('find /n "" %2')


The first: leave out the caret
The second: leave out the redirect, find does not need it
by OJBakker
02 Dec 2011 19:12
Forum: DOS Batch Forum
Topic: what is wrong with IF else, please help me
Replies: 7
Views: 3394

Re: what is wrong with IF else, please help me

? EQU is correct, EQL does nothing. Personally I prefer using == for EQU comparisons. You are right. I got EQL from if /? (Vista language: dutch) EQL - is gelijk aan NEQ - is niet gelijk aan LSS - kleiner dan LEQ - kleiner dan of gelijk aan GTR - groter dan GEQ - groter dan of gelijk aan I always u...
by OJBakker
02 Dec 2011 10:25
Forum: DOS Batch Forum
Topic: what is wrong with IF else, please help me
Replies: 7
Views: 3394

Re: what is wrong with IF else, please help me

A minor syntax problem might be the problem.
change EQU to EQL
by OJBakker
25 Nov 2011 02:39
Forum: DOS Batch Forum
Topic: Limit CMD processing to internal commands, safer and faster?
Replies: 16
Views: 9769

Re: Limit CMD processing to internal commands, safer and fas

These are not the same: set "PathExt=" set "PathExt=;" The first deletes the PathExt from environment. CMD falls back to internal default:.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC The second set PathExt to: No extensions to search for. I have tested some more just to be sure: Disabli...
by OJBakker
23 Nov 2011 02:46
Forum: DOS Batch Forum
Topic: Limit CMD processing to internal commands, safer and faster?
Replies: 16
Views: 9769

Re: Limit CMD processing to internal commands, safer and fas

If I set the path to nothing DOS will not search the path for a file named echo when echo. right ? Almost, just disabling path is not enough. FileSearch will still be done in the current directory. That is why the FileExt has to be disabled as well. I was wondering if it also has effect on performa...
by OJBakker
22 Nov 2011 15:16
Forum: DOS Batch Forum
Topic: How to check if parameter is file (or directory)?
Replies: 8
Views: 4671

Re: How to check if parameter is file (or directory)?

A similar solution using only the file-attributes.

Code: Select all

@echo off&setlocal enableextensions
set attr=%~a1&set otype=?
if defined attr if "%attr:~0,1%" == "d" (set otype=D) else (set otype=F)
echo otype=%otype%
by OJBakker
22 Nov 2011 05:08
Forum: DOS Batch Forum
Topic: Limit CMD processing to internal commands, safer and faster?
Replies: 16
Views: 9769

Re: Limit CMD processing to internal commands, safer and fas

hmmm I guess my explanation was not very clear. I started with Jebs "Call Set" - "Set.bat" vulnerability. Tried to encapsulate the Call Set to isolate this from de FileSearch. Then I expanded my test to all internal commands. I can confirm that all internal commands are vulnerabl...
by OJBakker
21 Nov 2011 17:51
Forum: DOS Batch Forum
Topic: Limit CMD processing to internal commands, safer and faster?
Replies: 16
Views: 9769

Re: Limit CMD processing to internal commands, safer and fas

Restoring the path is not a requirement, just good practice. Imagine working from the commandline. You run a batchfile that wipes the path and does not restore it before finishing. Suddenly your external commands don't work anymore. Just because these are normally found through the default path-sear...
by OJBakker
21 Nov 2011 17:11
Forum: DOS Batch Forum
Topic: Limit CMD processing to internal commands, safer and faster?
Replies: 16
Views: 9769

Limit CMD processing to internal commands, safer and faster?

In the thread CALL me, or better avoid call at http://www.dostips.com/forum/viewtopic.php?f=3&t=1947&hilit=precedence Jeb demonstrated the slowness and unsafety of 'call set' and 'call echo' The code below is an attempt to tackle both problems. This is done by skipping the superfluous direct...