Search found 9 matches

by bluesxman
2023-Jan-16, 9:05 am
Forum: Windows CMD Shell
Topic: Can this be done with a FOR loop?
Replies: 1
Views: 175

Re: Can this be done with a FOR loop?

You're probably looking for something like this: @echo off REM location of a text file containing the list of directories set "dirlist=D:\Some Directory\dirlist.txt" for /f "usebackq tokens=*" %%a in ("%dirlist%") do ( call :subroutine "%%~a" ) goto :EOF :subr...
by bluesxman
2023-Jan-05, 10:07 am
Forum: Windows CMD Shell
Topic: Read a file, output each line to a new file, preserve all characters?
Replies: 7
Views: 470

Re: Read a file, output each line to a new file, preserve all characters?

GOD wrote: 2023-Jan-03, 1:04 pm You really do write some adorable cute code.
Thanks, I was going for "functional and concise, with a hint of 'inoffensive'" but these days I'll take whatever compliments I can get.
by bluesxman
2022-Dec-26, 10:42 am
Forum: Windows CMD Shell
Topic: Read a file, output each line to a new file, preserve all characters?
Replies: 7
Views: 470

Re: Read a file, output each line to a new file, preserve all characters?

Have you tried something like this approach? setlocal disabledelayedexpansion set /a count=0 for /f "useback tokens=* delims=" %%L in ("your_file.txt") do ( set "line=%%L" call :write_file ) goto :EOF :write_file set /a "count+=1" REM your conditional changes ...
by bluesxman
2022-Aug-04, 5:13 pm
Forum: Windows CMD Shell
Topic: How to replace all characters in a variable with another character?
Replies: 2
Views: 1049

Re: How to replace all characters in a variable with another character?

I don't think there's a straight forward way to do that. You could use this https://ss64.com/nt/syntax-strlen.html To measure the string length and then form a string of * of the right length So, for example: @echo off set "foo=qwertyuiop" set "bar=" call :strlen foo foo_len setl...
by bluesxman
2022-May-13, 11:21 am
Forum: Windows CMD Shell
Topic: position variables in substring extraction use octal number recognition
Replies: 1
Views: 826

Re: position variables in substring extraction use octal number recognition

Interesting, don't remember noticing that before ... but doesn't altogether come as a surprise, given that other numeric handling interprets octal. S:\>if 8 EQU 010 echo hello octal hello octal S:\>set /a x=010 8 Good to know for potential gotchas though! There is, however, an interesting divergence...
by bluesxman
2022-Apr-14, 8:45 am
Forum: Windows CMD Shell
Topic: How to differentiate between similar filename extensions?
Replies: 6
Views: 1616

Re: How to differentiate between similar filename extensions?

Maybe something like this?

Code: Select all

for %%F in (*) do set /a "EXT%%~xF+=1"
set EXT.
This should count all the extensions, if you only care about a few you can just pick those up like %EXT.jpe%
by bluesxman
2022-Apr-12, 3:36 pm
Forum: Windows CMD Shell
Topic: How to differentiate between similar filename extensions?
Replies: 6
Views: 1616

Re: How to differentiate between similar filename extensions?

I don't think it's treating it as a wildcard exactly, I think you're probably coming up against weirdness from 8.3 filenames S:\>dir /x <snip> 12/04/2022 16:32 2 hello.jpe 12/04/2022 16:32 2 HELLO~1.JPE hello.jpeg 12/04/2022 16:32 2 hello.txt 12/04/2022 16:32 2 HELLO~1.TXT hello.txt1 12/04/2022 16:3...
by bluesxman
2021-Sep-06, 7:16 am
Forum: Windows CMD Shell
Topic: How to create a variable with arguments starting at 2 positions ?
Replies: 4
Views: 4339

Re: How to create a variable with arguments starting at 2 positions ?

I agree, it feels like there should be a more elegant solution -- but keeping it robust is tricky without knowing more about the expected input. The only other thing I had in mind was a FOR loop, but it doesn't look any better to me (while probably being marginally worse on performance due to the re...
by bluesxman
2021-Sep-03, 11:21 am
Forum: Windows CMD Shell
Topic: How to create a variable with arguments starting at 2 positions ?
Replies: 4
Views: 4339

Re: How to create a variable with arguments starting at 2 positions ?

SHIFT set arguments=%* I don't think that will work Simon, AFAIK %* always contains all of the original args, regardless of "shift" invocations. You'd probably have to do something like this: @echo off set "args=" call :argloop %* set args goto :EOF :argloop shift if "%~1&q...