Solved

How do I parse a filename?

Posted on 2004-08-26
3
658 Views
Last Modified: 2010-10-05
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.
0
Comment
Question by:seckel
3 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 11906908
Give this a try:

@echo off

setlocal

for /f "delims=" %%a in ('dir /b test_???_???.txt 2^>NUL') do call :PROCESS "%%a"

goto :EOF

:PROCESS

set FileName=%~1

echo File name:   %FileName%
echo Department: %FileName:~5,3%

Good Luck,
Steve
0
 
LVL 6

Expert Comment

by:mrdtn
ID: 11906940
@echo off
setlocal enabledelayedexpansion

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

Author Comment

by:seckel
ID: 11911876
Steve

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

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question