I mentioned in my last post that I'm still very inexperienced with this, so I'm sure I'm doing something basic wrong, but for some reason I can't get what I think is simple code to work.
In this example there are several text files in a directory with names like:
Example File--1000.txt
Another File--2500.txt
One More--3879.txt
Every filename is a different length, but they all end with a four digit number separated by "--" (i.e. file--0000.txt). My goal is to extract those 4 digits as a variable so that I can manipulate it and rename the files based on what number they end with. Here's the part of the code I'm struggling with:
Code: Select all
@echo off
for /F "tokens=1,2 delims=--" %%G in ('dir /b *.txt') do (
echo Result: %%H
echo.
set DelimitedFilename=%%H
echo DelimitedFilename: %DelimitedFilename%
echo.
set FourDigitNumber=%DelimitedFilename:~1,4%
echo Four Digit Number: %FourDigitNumber%
echo.
)
I'm able to get 0000.txt, but I can't seem to set the first variable, and so it ends up with blanks:
Code: Select all
Result: 1000.txt
DelimitedFilename:
Four Digit Number:
Result: 2500.txt
DelimitedFilename:
Four Digit Number:
Result: 3879.txt
DelimitedFilename:
Four Digit Number:
Any help would be appreciated... as dumbed down as possible :) Thanks!