Batch - removing the path from %1

M

M Bourgon

Very basic, newbie batch question.
I am creating a batch file for Windows that will take the file dropped
upon it (the %1), and get the actual filename without the extension.

What I'm trying to run is ffmpeg, setting the output file to be a
different folder & filename than the input. So it would be something
like:
ffmpeg -i "%1" -f mp4 -title "HereIWantTheBaseFilename" -vcodec copy -
acodec copy "D:\holding_area\HereIWantTheBaseFilename.mp4"

So when I drop the file on it, which would invoke:
test.bat c:\my\stuff\test.avi
Once done, I'd wind up with file D:\holding_area\test.mp4

I know how I'd do it in SQL (REVERSE the variable, find the first
backslash, do the same to figure out where the "." is, SUBSTRING it to
a variable, and voila), but I have no idea where to start with a batch
file.

Any help greatly appreciated.
 
B

Bill Blanton

M Bourgon said:
Very basic, newbie batch question.
I am creating a batch file for Windows that will take the file dropped
upon it (the %1), and get the actual filename without the extension.

What I'm trying to run is ffmpeg, setting the output file to be a
different folder & filename than the input. So it would be something
like:
ffmpeg -i "%1" -f mp4 -title "HereIWantTheBaseFilename" -vcodec copy -
acodec copy "D:\holding_area\HereIWantTheBaseFilename.mp4"

So when I drop the file on it, which would invoke:
test.bat c:\my\stuff\test.avi
Once done, I'd wind up with file D:\holding_area\test.mp4

Try;

@echo off
for %%F in (%1) do set BASENAME=%%~nF
echo D:\holding_area\%BASENAME%.mp4
pause


type
FOR /?
at the cmd prompt for more information.
 
M

M Bourgon

Try;

@echo off
for %%F in (%1) do set BASENAME=%%~nF
echo D:\holding_area\%BASENAME%.mp4
pause

type
FOR /?
at the cmd prompt for more information.

Wow. I had no idea the FOR command would do all that. MANY thanks!

M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top