List To MultiInstance aka L2M

version 2005.1.3.180

Freeware for any purposes. AS IS.

Program was developed as Total Commander add-on, but can work as standart 
application.


!!!!

By First. Sorry for my English. My native languages is Russian & Pascal =)


PROBLEM AND SOLVE

Frequently there is a need to start the program and to pass to  the program as 
parameters some files. Many programs can open some files (MDI-application) or 
start self copies for each file (SDI-application). But count of programs, which 
can correctly process a set of files passed to it in the command line, is very 
few. Usually a program only open first file in command line, all other files are 
rejected, or names of all passed files is considered as continuation of a name 
of first file. 

So, for example, next command will start the Notebook for file "1.txt":

  notepad.exe "1.txt" "2.txt" "3.txt"

The following command will start a notebook for a file "1.txt 2.txt 3.txt":

  notepad.exe 1.txt 2.txt 3.txt

Some programs (for example, the Russian antiviruses AVP and DrWeb) can accept a 
name of a file, which include the list of the necessary files. Such programs 
execute necessary operations for each file in the list. Total Commander is able 
to create such files and to pass them as parameters (more about it look in Total 
Commander  help files). Total Commander put in the list-file selected files (or 
file under cursor if nothing is selected).

Respectively, if the program does not accept as parameter the list-file, You 
have to start it for each file manually. More correctly it was necessary 
earlier. Now you have "List To MultiInstance"

How It Work?

You pass to l2m.exe a filename of program which you want to start parameter 
(optional) and filename of list-file, which include filenames of files needed to 
open. You also can pass some additional parameters.

Usage Syntax:

	l2m.exe /L:<List file> [/X:<Execute program>] [/B:<before param>] 
	[/E:<end param>] [/W] [/S] [/P] [/F:<pause>] [/G:<gui mode>] 
	[/R:<RegExp>] [/I] /J:<project>] [/M:<window_mode>] [/O:<priority>]

	or

	l2m.exe <filename> (see "Drag&Drop in Total Commander" below)


	,where:

	<Exe file> - Program which will be started for each file in file-list. 
	If <exe file> absent then will be started program, default for file in 
	list.

	<List-file> - list of files which will be opened

	<B-Params> - string (parameters), which will be inserted before name of 
	file from <list-file> before this command will be execute. May be 
	absent.       

	<E-Params> - string (parameters), which will be inserted after name of 
	file from <list-file> before this command will be execute. May be 
	absent.

	<milliseconds> - If this parameter is present L2M make pause of 
	<milliseconds>  before open second file. <milliseconds> may be equals 
	zero. If /P key also present /F-key ignored. Default pause is 1 second 
	(see also "WinAMP playlist")

	/W - if this parameter is present, L2M not wait while executing program 
	open the file. By default, L2M wait. May be absent.   

	/S - switch method of execute program to alternative. (If you are want 
	to know, first method is use CreateProcess function and second - 
	ShellExecuteEx function)

	/P - if this key is present, L2M wait while previous opened file will be 
	closed. You can skip waiting process for file by "Skip" button in main 
	dialog. (see also "MDI Application and /P")

	/G - switch showing GUI. Number after ":" set followed mode:
	0 - GUI hasn't been show (!!! You'll can't cancel process)
	1 - GUI hasn't been show if there only one file in list (default)
	2 - GUI has been show only if /P-key is present 
	3 - GUI has been show always

	/R - <reg_exp> string, which used as regular expression. This regexp 
	appled to each file in <List_file> and it's matches may be used in 
	<B-param> and <E-Param> (see "Work with Regular Expression" below)

	/I - if this parameter is present l2m show dialog in which you can 
	change or add any parameters. You will can cancel operation also.

	/J - string which used as project name. Project is a set of befo saved 
	parameters (see "Work with projects" below)
	
	/M - swith window mode for running application. Number after ":" set 
	followed mode:
	0 - hidden
	1 - normal (default)
	2 - minimased
	3 - maximased

	/O - set the priority of running application. Number after ":" set 
	followed mode:
	0 - normal (default)
	1 - low
	2 - high
	3 - real-time



l2m.exe starts for each file from <List-file> the application <Exe file> (or associated application), pass it, <b-params> and <e-params> as parameter. If regular_expression exists It applyed to filename name and it's result uses in <b-params> and <e-params>. 

If l2m has not parameters or some parameters except /L and /I present - l2m show usage syntax. If parameter /I is present the dialog window is show.

If l2m has only one parameter and this parameter is filename - this file is executing.

During working process of L2M progress window is showing. In this window you can see progress of opening files from list and can skip open current file and cancel whole opening process.

For example. 

Let "list-file.txt" content is:
   c:\1.txt
   c:\2.txt
   c:\autoexec.bat

And you enter such command in RunDialog or MS-DOS Prompt or in WindowsCommander, 
Far etc:

 l2m.exe /X:notepad.exe /L:list-file.txt

After you press "Enter" "List To MultiInstance" execute this commands:

	notepad.exe c:\1.txt

then 

	notepad.exe c:\2.txt

and finally 
	notapad.exe c:\autoexec.bat

Now you have 3 Notepad with opened files in its. Enjoy =)

Well, I think what it is possible  to receive the best results and pleasure only 
having attached this programs to Total Commander. 


HOW TO ATTACH TO TOTAL COMMANDER? 

Create menuitem of Start-menu or Toolbar button and specify so: 

The command: <Path to lst2mlt>\l2m.exe 
Parameters: /X:"<Path to exe file>" /L:"%L"

So, for example, for EditPlus2 on my computer the command look so: 

The command: c:\wincmd\lst2mult.exe 
Parameters: /X:"C:\Program Files\EditPlus 2\editplus.exe" /L:"%L" 

Instead of %L you can use %l, %F, %f, %D, %d.  Look Help if Total Commander. 
Now select files and run created menu- or toolbar- command.

Enjoy =). It's Free =). And only for you =)


PRE- AND POST- PARAMETERS.

If program which open file from list can parse addition parameters passed from 
command line, you can add its to L2M parameters and its has been added to each 
file in list. Some program require parameters before file name, another - after 
filename and another don't make differences. List To MultiInstance allow use any 
way fro pass parameters.

For example, NullSoft WinAmp allow enqueue file passed to it and dont play file 
immediately. To do this you must set "Enqueue as default action" in WinAmp 
settings. But let you don't want to set default action as Enqueue. Then you can 
add file to enqueue by command like:

	winamp.exe /ADD <path to mp3-file>

If you want add many files to winamp playlist you can use L2M aby command like 
(in Total Commander):

	/B:/ADD /L:"%L" /X:"C:\Program Files\Winamp\winamp.exe" /W


Work with Regular Expressions

Sometimes there is a necessity to process each file in list, but command to 
process is depended from processed filename. For example, it is necessary to 
make a copy selected files in the same folder, but with change it's extension to 
".bak". L2M allow you to make regular expresion, which extract filename without 
extension. And then this part of filename can be connected with new extension in 
<b-param> or <e-param>. The command for this example is such (not work on files 
without extension!):

l2m /X:cmd.exe /B:"/C copy" /L:<list> /E:"$1.bak" /R:^(.+\\[^\\]+)\..+?$  

L2M find expression from parentheses in <RegExp> and then substitute result 
instead of a variable $1 in <end param> 


Work with Projects

Project is a list of parameters saved with some name. Youc can save in the project any keys except /I and /J key. In the project it is possible to save not all parameters - in this case  saved parameters are equal to it's default values.  In the project it is possible to save parameters with empty values (for string) - then these parameters will be empty strings. 

In addition to /J key it is possible to have any other keys in command line. This keys can add or change parameters in project. Addition /J key can be included in command line.

Except for a key of the task of the project in a command line also can  other keys supplementing or  parameters of the project, including keys of other projects.

It is necessary to understand, that next key replaces the previous value of parameter, and the project replaces only those parameters which in it are was saved. 

Example. There is a project "test" in which parameters <Exe_file>=editplus.exe and <Before_param> =/p are saved. Then the following commands will lead to such results:

Command: l2m /X:<notepad.exe> /J:test /L:dummy.lst 
Result: editplus.exe /p <a file from the list>

Command: l2m /J:test /X:<notepad.exe> /L:dummy.lst 
Result: notepad.exe /p <a file from the list>

Lets still there is a project "wait_close", in which the keys /P <Pause>=1 and <exe_list>=listedit.exe was saved. Then the following commands will lead to such results:

Command: l2m /X:<notepad.exe> /J:test /L:dummy.lst /J:wait_close
Result: listedit.exe /p <a file from the list> (with waiting of close)

Command: l2m /J:test /J:wait_close /X:<notepad.exe> /L:dummy.lst
Result: notepad.exe /p <a file from the list> (with waiting of close)

Command: l2m /J:wait_close /X:<notepad.exe> /L:dummy.lst /J:test
Result: editplus.exe /p <a file from the list> (with waiting of close)


The project can be created from a dialog mode (most convenient) or in a manual 
mode. 
In a dialogue mode it is necessary to define need parameters, then press button 
"Save". In a new window it is necessary to set a name of the project and to 
specify what parameters are saved. To load the project in a dialog window, it is 
necessary to choose it from the combobox and to press the button "Load". 
Repeating last operation, it is possible to load some projects (similarly to 
their indication in a command line).
Except for a dialogue mode it is possible to use direct editing a file 
%USERPROFILE %\Local Settings\Application Data\Tnn\L2m\projects.ini.



NOTES.


Drag&Drop in Total Commander (at present time - v6.50)

Many users make button on Total Commader toolbar to lunch favorite program. It's 
posible to drag file on this button to lunch assotiated program and pass dragged 
file to it. But this method have some limits. By the first, Total Commander pass 
only one file to program even if you select some files. By the second, all 
parameters is ignored - only program and filename as parameters. This is feature 
of Total Commander.

What is why if you drag and drop filename on button, which execute List To 
MultiInstance, no parameters /X and /L (and other of course) has been passed. In 
this case L2M execute program associated with extension of passed file.


WinAmp Playlist.

WinAmp is slick. For example, if you lunch mp3-file, then WimAmp clear current 
playlist and create new one. In this playlist it add you mp3 file. If you wait 
one or two second and repeat mp3 file lunching procedure , then situation will 
repeat too - new palylist and single file in it.

But if you lunch mp3 files very fast and dont make pause between lunches, then 
WinAmp also create new playlist after lunch first file, but lunching next files 
don't clear this playlist and all next files will be added to one playlist.

Before version 1.5 List To MultiInstance always make pause in one second after 
lunch first file to give program time to execute. This behaviour is conduce to 
situation when firs file didn't added to playlist =(.

Sinec v1.5 you can set pause between first and second file lunching by passing 
/F key. You have to select pause value which allow to start Winamp, but not 
allow lose first file in play list. If you have new powerful computer you can 
try to pass /F:0


MDI-application and /P key.

MDI (Multi Document Interface) application open all files inside one process, 
but SDI (Single Document Interface) open ech fiel in new process. For example, 
Adobe Photoshop - MDI application, but MSPaint - SDI Application.

The /P key tell List To MultiInstance to wait while previous opened file will be 
closed, but with MDI Application we have problem. To understand why we have 
problem, we must know how MDI apllication open files.

It's simple. When you lunch some file, windows execute application associated 
with file extencion and pass your file as parameter. SDI application just open 
passed file. True MDI application seek already executed self copy and , if 
found, send message to the copy. Messsage contain filename to open. After this 
new started MDI application close, and previous copy is open passed file.
If MDI appliction don't found self copy then it open file itself

When L2M lunch application, Windows return application handle by which L2M wait 
for application terminate (if /P key present, of course). 

If MDI application found self copy, then it close immediately and L2M receve 
message what application terminated and L2M lunch next file. In other words, L2M 
wait when application close, but not when file close.

For right work L2M with  MDI apllications and /P key please always close 
application - don't use Skip button. In other case all files will be opened 
without pauses (like /P key is absent). Pause will be only between first and 
second files.

Microsoft Office and a /S key.

When you transfer in L2M the list of files not specifying application to execute 
(a /X key is not specified), for each file the associated application is 
started. In depending on presence of a /S key the behaviour CAN BE various. Most 
typically it is shown at open of files of MS Office. If the /S key is absent (in 
this case the function CreateProcess is used) each file in the list opens in 
separate process. If /s key is present (this case the function ShellExecuteEx is 
used) - the file will be open as the separate document, but inside one process. 
Such behaviour speaks that for opening files MS Office is use DDE technology. In 
current version L2M this technology is not applied. Function ShellExecuteEx uses 
this technology internaly, that allows to process files MS Office properly.


List To MultiInstance, Copyright  2001-2005 by Tir Na Nog, All right reserved. 
WWW:    http://tirna.narod.ru 
E-Mail: mailto:tirna@narod.ru

This program use such libraries: 
1 TRegExpr v. 0.947 2001.10.03  
  Copyright (c) 1999-2001 by Andrey V. Sorokin <anso@mail.ru>