string - Get base name of file without file extension -
let's i'd have file named "testfile.txt" set on variable:%file% , i'd remove extension when echoing . echo %file:~0,8% come out "testfile" want have display , left of ".txt" because won't make files have 8 characters in name.
is there simple solution ?
yep.
for %%i in ("testfile.txt") echo %%~ni or
for %%i in ("%file%") echo %%~ni do help for in cmd console window , see last 2 pages more information on tilde operations.
there way accomplish want, using substring substitution similar attempts illustrated in question.
set "file=testfile.txt" echo %file:.=&rem;% that substitutes dot &rem;. when variable evaluated, batch interpreter treats newly substituted data compound command. , since following rem treated remark ignored, you're left testfile output. work if:
- you don't include quotation marks in variable value
- your filename includes 1 dot
- you don't within parenthetical code block (
ifstatement orforloop) delayed expansion required
Comments
Post a Comment