files with extra suffix in batch -
i'm trying list files have suffix after extension e.g: .txt.1 or .txt.2 etc..
i'm using txt. it's giving file names instead of files suffix
for %%a in (*txt.*) (call :renum "%%a")
after i'm writing program rename files accordingly. can please check , help.
one solution filter extension inside loop:
for %%a in (*txt.*) ( if not "%%~xa"==".txt" call :renum "%%a" )
this works using "enhanced substitution of for
variable references", in case %%~xa
. can overview of available substitutions executing for /?
.
update:
- this solution not work case-insensitively, because neither explicitly demanded or prohibited. use
if /i
instead of plainif
if case-insensivity desired. - as dbenham notes, there edge cases:
name.txt.txt
will not processed. if that's ok not stated, rather likely.name_txt.ext
will processed, due given wildcard*txt.*
, can avoided using*.txt.*
instead. rationale not change in first place op knows actual set of files, , assumed had reason choosing (a situation common in these types of questions).
Comments
Post a Comment