Search found 93 matches

by OJBakker
09 Dec 2024 05:31
Forum: DOS Batch Forum
Topic: Split a filename containing wildcards in path and name without expanding the wildcards
Replies: 6
Views: 8802

Re: Split a filename containing wildcards in path and name without expanding the wildcards

Antonio Sorry for the confusion. You are entirely right. Somehow the name variable got stuck in my environment and I had not noticed that when I experimented with your code. So I changed the code to solve a non-existing problem, but in doing so I showed that it can cause problems when a variable is ...
by OJBakker
07 Dec 2024 03:31
Forum: DOS Batch Forum
Topic: Split a filename containing wildcards in path and name without expanding the wildcards
Replies: 6
Views: 8802

Re: Split a filename containing wildcards in path and name without expanding the wildcards

Antonio Your code gives incorrect output for the path: filename=c:\one\two\*\four\*.c path=c:.c\one\two\*\four name=*.c I have made a modified version: @echo off setlocal EnableDelayedExpansion set "filename=c:\one\two\*\four\*.c" @for %%A in (f_path f_name fname) do set "%%A=" set "f_path=%filename...
by OJBakker
30 Nov 2024 04:42
Forum: DOS Batch Forum
Topic: Substring extraction fails in reverse order
Replies: 2
Views: 7769

Re: Substring extraction fails in reverse order

@echo off cls setlocal set "Str=ABCDE" set "StrTmp=%Str%" if not defined StrTmp goto :end set /a i=0 :loop set /a i+=1 rem extract last character set Ar[%i%]=%StrTmp:~-1,1% rem remove last character from string set StrTmp=%StrTmp:~0,-1% rem check if string still exists (has more characters) if defi...
by OJBakker
25 Aug 2024 12:19
Forum: DOS Batch Forum
Topic: Batch file question
Replies: 2
Views: 40275

Re: Batch file question

Your batchfile does what you tell it to do. By using only the drive specifier and not specifying the directory on that drive you are saying use the current direcory on the sourcedrive and the current directory on the destination drive. That is not what you intended but it is how it works. Flexibilit...
by OJBakker
29 Apr 2024 08:13
Forum: DOS Batch Forum
Topic: Need help with misbehaving DOS code
Replies: 2
Views: 10077

Re: Need help with misbehaving DOS code

The timeout command is never reached in your code. You end your code with the 'goto :eof' line which stops the processing. You can add a label before the timeout-command and change the goto :eof to jump to this new label. Or move the timeout-command to within the if-command so the timeout will be ex...
by OJBakker
23 Mar 2024 03:24
Forum: DOS Batch Forum
Topic: if/elseif dont work like expected...Sorry, this time in English
Replies: 3
Views: 10108

Re: if/elseif dont work like expected...Sorry, this time in English

if /I "%~1"=="/help" ( ECHO Ausgabe Hilfe cmd /k ) else if NOT exist "%~1" ( ECHO Datei existiert nicht^! Abbruch^! cmd /k ) else if /I "%~x1"=="" ( ECHO Keine DateiErweiterung^! Abbruch^! cmd /k ) else if /I NOT "%~x1"==".txt" ( ECHO DateiErweiterung ist nicht txt^! Abbruch^! cmd /k ) else if /I "...
by OJBakker
16 Mar 2024 15:11
Forum: DOS Batch Forum
Topic: Need Help: CALL subroutine in Batch dont worl like expected
Replies: 2
Views: 7489

Re: Need Help: CALL subroutine in Batch dont worl like expected

You are using the first parameter supplied to your subroutine in your subroutine.
But in the main batchfile you are not calling the subroutine with a parameter.
by OJBakker
10 Nov 2023 15:31
Forum: DOS Batch Forum
Topic: ECHOing to a file without a trailing space
Replies: 6
Views: 28724

Re: ECHOing to a file without a trailing space

Place the redirect before the echo to avoid the trailing space in the echo command.

Code: Select all

>file0.tmp echo %field1%;%field2%;%field3%
by OJBakker
22 Oct 2023 02:02
Forum: DOS Batch Forum
Topic: [SOLVED] Validating user input against the content of a text file
Replies: 3
Views: 19258

Re: Validating user input against the content of a text file

Your code creates variable valid_disks with all valid disknumbers separated by spaces. You test for valid disknumber by checking if the entered disknumber with a leading and a trailing space is found in the valid_disk variable. The first disknumber in valid_disk will not have a leading space and the...
by OJBakker
13 Oct 2023 09:56
Forum: DOS Batch Forum
Topic: Variable inside an IF not showing correctly
Replies: 18
Views: 125722

Re: Variable inside an IF not showing correctly

You are halfway correct.
You have corrected the first "if not exist" but not the second one. There the errorlevel and errlev variables have to be corrected as well.
by OJBakker
13 Oct 2023 04:58
Forum: DOS Batch Forum
Topic: Variable inside an IF not showing correctly
Replies: 18
Views: 125722

Re: Variable inside an IF not showing correctly

Your problem is that you are using %errorlevel% in a () codeblock. Because of the codeblock %errorlevel% will give the value of the errorlevel special variable at the start of the codeblock and not the errorlevel as returned by xcopy or robocopy. Change the line echo %errorlevel% to echo !errorlevel...
by OJBakker
26 Sep 2023 11:42
Forum: DOS Batch Forum
Topic: :Concatenate function, advanced version, custom separator, multiple inputs, byval, byref and byref array ! (but oneprob)
Replies: 5
Views: 20275

Re: :Concatenate function, advanced version, custom separator, multiple inputs, byval, byref and byref array ! (but onep

I have attached 3 adapted versions of Concatenate-DEMO-For batch file. Your version uses a for /f loop to save over endlocal. The -For version is the shortest. It uses a for loop and for-param to save over endlocal. The -NoFor version uses no for but escapes the linefeeds before saving the param ove...
by OJBakker
24 Sep 2023 18:52
Forum: DOS Batch Forum
Topic: :ForIF Function, evaluates arguments like a IF inside a for (but there's strange behaviour ?)
Replies: 2
Views: 6827

Re: :ForIF Function, evaluates arguments like a IF inside a for (but there's strange behaviour ?)

You are using string-compare where you expect to do numerical-compare.

Examples:
if "2" LSS "10" (echo TRUE) else (echo FALSE)
False
explanation: "2 " > "10"

if "02" LSS "10" (echo TRUE) else (echo FALSE)
True

if 2 LSS 10 (echo TRUE) else (echo FALSE)
True
by OJBakker
24 Sep 2023 18:14
Forum: DOS Batch Forum
Topic: batchfile fails to delete unwanted files
Replies: 15
Views: 26026

Re: batchfile fails to delete unwanted files

Wow, what a mess you have created. :? :cry: You seem to be incapable of reading/following the most elementary instructions! By starting with running the corrected code from Batcher you yourself have deleted the bookmarkfiles! This confirms that your problem file had no permissions problem. An attrib...
by OJBakker
24 Sep 2023 08:01
Forum: DOS Batch Forum
Topic: batchfile fails to delete unwanted files
Replies: 15
Views: 26026

Re: batchfile fails to delete unwanted files

Yep, I am from the Netherlands and Dutch is my primary language so sometimes my English will have a 'touch of Dutch'. And my id at this forum is OJBakker, not OJBaker :lol: Your use of the term 'manually' is ambiguous. For you it apparently means: manually from the windows gui using windows explorer...