INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Send To -> Passing variables to the command line  (Read 5673 times)

ubernode54

  • Junior Woodchuck
  • **
  • Posts: 71
Send To -> Passing variables to the command line
« on: June 01, 2008, 08:46:15 pm »

I'm trying to use the 'send to' feature to run some personal programs from MC. What I want to do is from the file view, right click a folder and then send the folder path as a variable to the command line program. Something like this:

Program Path: c:\windows\system32\cmd.exe
Parameters: do something with "[This Folder]"

So, what's the correct format of "[This Folder]" to get cmd.exe to 'do something' to it?

MC's default for the parameter is "[Filename]". I'm trying to emulate a program that runs from a right-click on a folder, and uses %L% as a parameter to pass the folder's path location to the program.
Logged

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Send To -> Passing variables to the command line
« Reply #1 on: June 02, 2008, 09:21:20 am »

MC can only pass filenames to external programs.

It's possible to extract the folder or rather the filepath of the file sent eg. with a batch file or vb script.

You can then use this path within a bacth script to process all files in that folder.

But you need to rememeber to send *only* one file from MC to do the whole folder otherwise the external program will get called repeatedly for each file in the selection.

Can get more specific if you mention which program you want to send to.
Logged

ubernode54

  • Junior Woodchuck
  • **
  • Posts: 71
Re: Send To -> Passing variables to the command line
« Reply #2 on: June 02, 2008, 12:37:31 pm »


Program I run is an integrity-checker, based on the contents of a folder which contains all tracks of a given album. The program is a batch file itself, run from the command line. It is normally called by right-clicking the directory and selecting a context menu item, of which the registry entry provides the following command:


cmd /T:1F /k cd "%L" && cd .. && [command --ini location switch] "%L"

As far as I gather, it calls cmd.exe, sets the color, remains, changes to the %L% (required directory location), moves to the parent directory (required for program, I suppose), then calls the program with it's required switches, and passes %L% to the program as a variable i.e. the directory to check.

Being able to select only one file would actually make my life easier, so that I can eliminate the additional step of locating the containing folder (within MC or otherwise). Just as I love the 'expand album' feature so that I can find the corresponding album files based on a single track.

If this proves to be easy enough, I'm sure I can figure out anything else I want to do.


Logged

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Send To -> Passing variables to the command line
« Reply #3 on: June 02, 2008, 02:11:10 pm »

Use "%~dp1" as the %L% variable in your batch file.

%~dp1 in DOS expands %1 to a drive letter and path of the file being passed.

Now add that batch file to the list by Send To->Send To external->Add/Edit programs.

Then to use it in MC,  just select 'a' file from an album and then do Send To->Send To external->your batch prog

You should see a cmd window pop up and see it display the results of your test.

NB: you do this in a file view and not the folder in tree view or it sends everything in that folder and you will see lots of cmd windows pop up ;)

Logged

ubernode54

  • Junior Woodchuck
  • **
  • Posts: 71
Re: Send To -> Passing variables to the command line
« Reply #4 on: June 02, 2008, 07:28:18 pm »

Thanks. Gettin' closer...

I created a batch file to do this:

Program: batch.bat
Parameters: "[Filename]"

The batch file is this:

cd %~dp1
%~d1
cd ..
pause

cmd /T:1F /k [command --ini location switch] "%~dp1"


I've never found out why when, in XP and cmd.exe, you cd to a different directory, you're not actually taken there. You have to enter the drive letter of the cd directory and then you're taken there. Thus the %~d1.

Everything works, up to the last "%~dp1". Problem is, the path is passed with a trailing backslash. The program errors-out when it see the '\' at the end of the variable %~dp1.

I thought perhaps an ascii escape sequence could take care of that, but apparently not?
Logged

glynor

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 19608
Re: Send To -> Passing variables to the command line
« Reply #5 on: June 02, 2008, 08:43:25 pm »

MC can only pass filenames to external programs.

That's not true!  This works fine:

Name:
Code: [Select]
IMDB (Name)Program Path:
Code: [Select]
C:\Program Files\Mozilla Firefox\firefox.exeParameters:
Code: [Select]
http://us.imdb.com//Tsearch?"[Name]"
This was changed some time ago.  MC can now send any tag, and can use expressions in the Parameters field of the Create Send To dialog.
Logged
"Some cultures are defined by their relationship to cheese."

Visit me on the Interweb Thingie: http://glynor.com/

hit_ny

  • Citizen of the Universe
  • *****
  • Posts: 3310
  • nothing more to say...
Re: Send To -> Passing variables to the command line
« Reply #6 on: June 02, 2008, 11:03:18 pm »

glynor, yes, it has changed since. I created these scripts yrs ago and never needed to do more :)

At the time, the only Tag required was [Filename].

Removing the trailing slash should be easier now with expressions

use RemoveRight([Filename],1)

instead of [Filename] in the external tools dialog.

Alternatively, you can pass just the filepath via the [Filename (path)] tag and then use "%1" (instead of  "%~dp1")  in the batch script, will still require to use RemoveRight([Filename (path)],1)
Logged

ubernode54

  • Junior Woodchuck
  • **
  • Posts: 71
Re: Send To -> Passing variables to the command line
« Reply #7 on: June 03, 2008, 12:43:13 pm »

Thanks a log hit!  ;D Finally got it working this morning.

You were right. I changed my batch file to simply %1 and passed RemoveRight("[Filename (path)]",1) as the parameter and it works wonderfully!
Logged
Pages: [1]   Go Up