Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.mp3In 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.

@echo off
setLocal EnableDelayedExpansionfor /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

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

![]() |
![]() |
![]() |

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