Sign in to follow this  
Followers 0
Tayundo

Trouble passing file path array to external program

4 posts in this topic

Hi there, and thanks for viewing. I am having trouble opening multiple files in an external program. I am attempting to open multiple instances of a video player using file paths acquired via FileOpenDialog in an array as the inputs. I have spent a couple hours trying various methods I Googled and I can't seem to figure this out on my own. My results are strange; the script will successfully open the first two files, but then creates one or more empty instances of MPC-HC depending on number of files selected.

 

My script is as follows:

 

$Babylon = @ScriptDir  & "\mpc.files\MPC.exe"
HotKeySet("^x", "Quit")  ;Shift+a

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

; Create a constant variable in Local scope of the message to display in FileOpenDialog.
Global Const $sMessage = "Hold down Ctrl or Shift to choose up to 8 files."

; Display an open dialog to select a list of file(s).
Global $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "Videos (*.avi;*.mpg;*.3gp;*.flv;*.mkv;*.mov;*.mp4;*.ogg;*.rm;*.rmv;*.mpeg)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
If @error Then
     ; Display the error message.
     MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")

     ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
     FileChangeDir(@ScriptDir)
   Else
     ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
     FileChangeDir(@ScriptDir)

EndIf

$aDays = StringSplit($sFileOpenDialog, "|") ; Split the string of days using the delimiter "|" and the default flag value.

ShellExecute(@ScriptDir & "\plumb.app\Plumb.exe","",@ScriptDir & "\plumb.app\") ; 3rd party window management.

For $pop = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
      ShellExecute($Babylon, "/new " & '"' & $aDays[1] & "\" & $aDays[$pop] & '"',@ScriptDir & "\mpc.files\")
      Sleep(1000)
Next

Sleep(5000)

While 1 ; Opens up a WHILE loop, with 1 as a constant, so it is infinite
If Not ProcessExists("mpc-hc.exe") Then Call("Quit"); if the process of MPC doesn't exist, it stops the script
Sleep (100) ; Puts the script to sleep for 100 milliseconds so it doesn't chew CPU power
WEnd ; Closes the loop, tells it to go back to the beginning

Func Quit()
   Local $process = ProcessList("mpc-hc.exe")

   For $i = 1 To $process[0][0]
   ProcessClose($process[$i][1])
   Next

   ProcessClose("Plumb.exe")

   msgbox (0, "Quit", "Thanks for using my script")

   Exit

endfunc

Thank you in advance for any help.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you look at the documentation for FileOpenDialog with multiple selections, the first selection has the directory followed by the filename.  The rest have only the filename since they are all chosen from the same directory.  You could either pass the working directory as changed by FileOpenDialog along in the ShellExecute call or add it onto the path names to make complete filenames for each command line param.

 

If you loop through and do a message box of the returned filenames after the StringSplit() you will see what I mean.

 

Edited by MilesAhead

Share this post


Link to post
Share on other sites

Thank you very much for your response. I appreciate anyone willing to toss some advice my way. That being said, I am aware of the array values: #arry[0] = number of strings returned, $array[1] = directory, $array[2] and on = delimited string values. I believe I am taking care of that in the snippet below. i am also passing the working directory in the same line.

 

ShellExecute($Babylon, "/new " & '"' & $aDays[1] & "\" & $aDays[$pop] & '"',@ScriptDir & "\mpc.files\")

 

In my tests this = mpc.exe /new "[initial_path]\[file_name+next number]"

Share this post


Link to post
Share on other sites

Hmmm, I can't seem to find the edit post button. 

What I meant by:
      In my tests this = mpc.exe /new "[initial_path]\[file_name+next number]"

is that each For should pass the directory and the next files name to MPC. Which works for the first two, but not the rest for some reason.

The full For/Next:

For $pop = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values.
      ShellExecute($Babylon, "/new " & '"' & $aDays[1] & "\" & $aDays[$pop] & '"',@ScriptDir & "\mpc.files\")
      Sleep(1000)
Next

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0