Solved

How do I parse a filename?

Posted on 2004-08-26
3
639 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
Comment Utility
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
Comment Utility
@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
Comment Utility
Steve

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now