Sign in with
Sign up | Sign in
Your question

BATCH file "grab filename"

Last response: in Windows 2000/NT
Share
Anonymous
May 13, 2005 12:55:25 PM

Archived from groups: microsoft.public.win2000.general (More info?)

Hi there, I need a .bat file that does this:

Looks at the directory it is executed from, and finds a single file
with a .wma extension. It stores this full filename in a variable, for
other executions.

There will only be one *.wma file per directory, but I do not know the
name of the file, only that it ends in "wma".

Here is a working version of what I have, where * is what needs to be a
variable.

@ECHO OFF
c:\windows\asfchop.exe -in *.wma -out *.asf -script timing.txt
DEL *.wma /q
PAUSE
DEL *.bat

The small batch uses Asfchop to merge a timing file with a video file,
and it works fine. But it does not work with a "*" wildcard, I need to
grab the actual filename.

Thanks Batch Wizards!
aqualizard
Anonymous
May 14, 2005 3:11:39 PM

Archived from groups: microsoft.public.win2000.general (More info?)

<aqualizard@gmail.com> wrote in message
news:1115999725.845033.312510@z14g2000cwz.googlegroups.com...
> Hi there, I need a .bat file that does this:
>
> Looks at the directory it is executed from, and finds a single file
> with a .wma extension. It stores this full filename in a variable, for
> other executions.
>
> There will only be one *.wma file per directory, but I do not know the
> name of the file, only that it ends in "wma".
>
> Here is a working version of what I have, where * is what needs to be a
> variable.
>
> @ECHO OFF
> c:\windows\asfchop.exe -in *.wma -out *.asf -script timing.txt
> DEL *.wma /q
> PAUSE
> DEL *.bat
>
> The small batch uses Asfchop to merge a timing file with a video file,
> and it works fine. But it does not work with a "*" wildcard, I need to
> grab the actual filename.
>
> Thanks Batch Wizards!
> aqualizard
>

Try this:

@ECHO OFF
for /F %%a in ('dir /b *.wma') do set FileName=%%~na
echo c:\windows\asfchop.exe -in %FileName%.wma -out %FileName%.asf -script
timing.txt
echo DEL %FileName%.wma /q
PAUSE
echo DEL *.bat

Remove every "echo" when satisfied with the batch file.
Anonymous
May 16, 2005 11:10:01 AM

Archived from groups: microsoft.public.win2000.general (More info?)

Thanks Pegasus,
it works as advertised and is terrific!

One small thing: Of course, my boss has now changed the specs on me.
Now it needs to do the same thing, but for EACH .wma in a directoy,
which will have a corresponding timer file with the same name (but a
..txt extension).

That is, for this directory listing:
123a.wma
722c.wma
123a.txt
722c.txt

It will use ASFCHOP in a loop to merge related WMAs with their correct
TXTs.

I am going to try figuring it out using the code you provided -- which
works great! -- but I must confess this BATCH stuff is unusual to me.
I know it is a simple FOR loop, and it looks like it MIGHT ALREADY BE
BUILT IN. (Maybe I just have to add %FileName%.txt!!)

Thanks so much!
aqualizard
Related resources
Can't find your answer ? Ask !
Anonymous
May 17, 2005 4:52:52 AM

Archived from groups: microsoft.public.win2000.general (More info?)

IMHO, Windows batch files are by far the worst among
programming languages when it comes to syntax or trying
to figure out how to do something. If you can work out how
to extend my sample code, without prior experience, then
you're doing pretty well! If you cannot, try this:

Line1 @ECHO OFF
Line2 for /F "tokens=*" %%* in ('dir /b *.wma') do call :Sub %%~n*
Line3 echo DEL *.bat
Line4 goto :eof
Line5
Line6 :Sub
Line7 echo c:\windows\asfchop.exe -in "%*.wma" -out "%*.asf" -script
timing.txt
Line8 echo DEL /q "%*.wma"

Remove every "echo" when satisfied with the batch file.

You could actually do the whole thing without calling a
subroutine. However, this would add yet another level
of complexity which tends to further confuse the issue.

<aqualizard@gmail.com> wrote in message
news:1116252601.471486.41090@g14g2000cwa.googlegroups.com...
> Thanks Pegasus,
> it works as advertised and is terrific!
>
> One small thing: Of course, my boss has now changed the specs on me.
> Now it needs to do the same thing, but for EACH .wma in a directoy,
> which will have a corresponding timer file with the same name (but a
> .txt extension).
>
> That is, for this directory listing:
> 123a.wma
> 722c.wma
> 123a.txt
> 722c.txt
>
> It will use ASFCHOP in a loop to merge related WMAs with their correct
> TXTs.
>
> I am going to try figuring it out using the code you provided -- which
> works great! -- but I must confess this BATCH stuff is unusual to me.
> I know it is a simple FOR loop, and it looks like it MIGHT ALREADY BE
> BUILT IN. (Maybe I just have to add %FileName%.txt!!)
>
> Thanks so much!
> aqualizard
>
Anonymous
May 17, 2005 1:45:05 PM

Archived from groups: microsoft.public.win2000.general (More info?)

Thanks so much for your help! This is what makes the Usenet great!
(That is, kindly strangers doing the work for people that don't have a
clue, that turn around and take the credit! Lol)

Anyway, there is a problem when I take the ECHOS off. It does the
first file successfully, but then says "Error in Line 1" (I removed the
first @ECHO OFF completely) and doesn't process the 2nd file.

I appreciate your help! I am almost there, but finding these batch
files...er... cryptic.

aqualizard
Anonymous
May 17, 2005 4:25:38 PM

Archived from groups: microsoft.public.win2000.general (More info?)

PLEASE DIREGARD THE LAST EMAIL!

Pegasus, your BAT file works as indicated!

THANK YOU!

I really, really appreciate your help. Having the working file that
you designed will save me several hours over the next few days.

Thank you so much,
aqualizard
PS: In case you are wondering what the problem was, it was an error in
the TIMING file, not your batch file.
Anonymous
May 18, 2005 12:16:49 PM

Archived from groups: microsoft.public.win2000.general (More info?)

Thanks for the feedback!


<aqualizard@gmail.com> wrote in message
news:1116357938.506578.319700@f14g2000cwb.googlegroups.com...
> PLEASE DIREGARD THE LAST EMAIL!
>
> Pegasus, your BAT file works as indicated!
>
> THANK YOU!
>
> I really, really appreciate your help. Having the working file that
> you designed will save me several hours over the next few days.
>
> Thank you so much,
> aqualizard
> PS: In case you are wondering what the problem was, it was an error in
> the TIMING file, not your batch file.
>
!