Search found 10 matches
- 2023-Jul-11, 12:59 pm
- Forum: Windows CMD Shell
- Topic: Best way to send contents of text file to the DIR command?
- Replies: 2
- Views: 8477
Re: Best way to send contents of text file to the DIR command?
I don't think there is a more elegant native way. My preferred syntax is: for /f "usebackq tokens=*" %%F in ("List.txt") do ( ... ) Incidentally, you probably want to protect your file names, vars with quotes -- in case of spaces/special characters. e.g. (untested) @echo off set ...
- 2023-Jan-16, 9:05 am
- Forum: Windows CMD Shell
- Topic: Can this be done with a FOR loop?
- Replies: 1
- Views: 1871
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...
- 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: 8
- Views: 6541
- 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: 8
- Views: 6541
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 ...
- 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: 2683
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...
- 2022-May-13, 11:21 am
- Forum: Windows CMD Shell
- Topic: position variables in substring extraction use octal number recognition
- Replies: 1
- Views: 2274
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...
- 2022-Apr-14, 8:45 am
- Forum: Windows CMD Shell
- Topic: How to differentiate between similar filename extensions?
- Replies: 6
- Views: 5147
Re: How to differentiate between similar filename extensions?
Maybe something like this?
This should count all the extensions, if you only care about a few you can just pick those up like %EXT.jpe%
Code: Select all
for %%F in (*) do set /a "EXT%%~xF+=1"
set EXT.
- 2022-Apr-12, 3:36 pm
- Forum: Windows CMD Shell
- Topic: How to differentiate between similar filename extensions?
- Replies: 6
- Views: 5147
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...
- 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: 6695
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...
- 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: 6695
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...