Computing.Net > Forums > Programming > strip file name to variable DOS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

strip file name to variable DOS

Reply to Message Icon

Name: goompa
Date: October 13, 2008 at 20:31:08 Pacific
OS: DOS XP
CPU/Ram: misc
Product: pc
Comment:

Hi there, may I borrow your brains please?

I run a radio station using winamp, wacommand, gawk, batch files and task scheduler. Mainly from batch files.

Anyways could I please have help, I just need to take the first part of a file name and place it into a variable.

eg.
1000.WEK (a file to track yesterdays file name prefix for MP3 files) needs to have the "1000" copied from the file name and made the value of the "PREFIX" variable.
This number will increment each weekday.
the "PREFIX" variable will then be used to identify today's audio program.
eg.
1000_programA.mp3
1001_programB.mp3
1002_programC.mp3

In this case "PREFIX" would identify "1000_programA.mp3" as being the file we need.

My main need is the ability to copy the "1000" from the file name to the variable. I'm fairly sure I can sort out everything else.

If anyone is curious on how I'm doing it at the moment gawk strips the number from a dat file then creates a variable.

Thanks for your help in advance.




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 13, 2008 at 21:35:37 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b filename') do (
set str=%%a
set prefix=!str:~0,4!
echo !prefix!
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: goompa
Date: October 14, 2008 at 03:11:47 Pacific
Reply:

Thanks so much for this, I'll try it out tomorrow.

You rock!


0

Response Number 3
Name: goompa
Date: October 14, 2008 at 13:45:28 Pacific
Reply:

OK I tried this and it worked perfectly. I missed the closing brackets at the bottom for the first 3 tries. It returned the error "%%a was unexpected at this time".
Once I sorted my life out and put the closing bracket in, it worked sweetly.
I'll include the details of how I'll use this soon.
Thanks again Mech


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: strip file name to variable DOS

DOS: Adding date to file name. www.computing.net/answers/programming/dos-adding-date-to-file-name/11491.html

BATCH text file content to variable www.computing.net/answers/programming/batch-text-file-content-to-variable/16264.html

Extract file name from file path www.computing.net/answers/programming/extract-file-name-from-file-path/16973.html