Link to home
Start Free TrialLog in
Avatar of seckel
seckel

asked on

How do I parse a filename?

Windows 2000 Professional.

I have files like this:

C:\temp
test_001_xxx.txt
test_002_xxx.txt
test_003_xxx.txt

The 001 is the dept code.  

I want to reference the dept code in various sections of my dos script.
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrdtn
mrdtn

@echo off
setlocal enabledelayedexpansion

for %%f in (*.txt) do (
      set file=%%f
      set dept=!file:~5,3!
      echo !dept!
)
pause
Avatar of seckel

ASKER

Steve

You are most wise and knowing when it comes to DOS....