Applying a command to the currently selected file only

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Applying a command to the currently selected file only

#1 Post by Quisquose » 13 Jul 2016 19:42

I am using the following batch file (which was written by somebody else) to perform a file conversion.

Code: Select all

@echo off
mkdir aac
for %%f in (*.m4a) do mp4box -raw 1 "%%f" -out "aac\%%f.aac"


It works fine, except for the fact that it applies the conversion command to ALL files with the .m4a extension in the current folder.

I am running the batch file from a context menu in Windows Explorer. I right-click on the file that I want to convert and select the menu item (that I created) to trigger the batch file. Therefore I only want the batch command to apply to file that I right-clicked on, and not to have the conversion applied to any other files at all.

How can I alter the above batch file so that it only applies to the one file that I right-clicked on, and leaves all the other files alone?

Thanks very much.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Applying a command to the currently selected file only

#2 Post by ShadowThief » 14 Jul 2016 02:41

I can't speak for running a script via right-click, but if you click and drag the file onto the script, the full path to that file gets passed to the script as %1, so you can just say

Code: Select all

mp4box -raw 1 "%~1" -out "aac\%~n1.aac"


It should work the same way for context menu items, but I'm not positive.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Applying a command to the currently selected file only

#3 Post by Squashman » 14 Jul 2016 05:40

ShadowThief wrote:It should work the same way for context menu items, but I'm not positive.

Yes. It does work that way as well. We do that here where I work.

Quisquose
Posts: 41
Joined: 13 Jul 2016 19:25

Re: Applying a command to the currently selected file only

#4 Post by Quisquose » 14 Jul 2016 06:23

ShadowThief and Squashman, yes this works perfectly from the context menu.

Thank you.

Post Reply