Jump to content

More selected files with $CmdLine


Recommended Posts

Hi,

When I select two or more files in the File Explorer of Windows and click on "Open" I want to know all the selected files i've selected.

My code is:

MsgBox(0,"Message","Script Started")

IF $CmdLine[0] > 0 Then
    For $i = 1 to $CmdLine[0]
        MsgBox(0,"Selected File",$CmdLine[$i])
    Next
EndIf

With one file it goes fine, but more files, I don't get the message "Script Started" (line 1 in my script).

The windows setting is for example: "D:\My Program.exe" "%1" (in Folder Options > File Types)

How do I solve this problem?

Thanks!

Edited by BartvanBeek
Link to comment
Share on other sites

Helpfile easily shows that $CmdLineRaw returns all the parameters

It also says it returns all parameters on one line so it may be easier to open the files with $CmdLine. I think 63 parameters is enough for most apps.
Link to comment
Share on other sites

  • Developers

Don't think the people responded understand the question. :P

I get when I set the compiled script to run when "Open" is selected for my ".tst" extension the following:

My test script runs as many times as the number of files selected.

Using WinXP sp3

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That honestly makes sense. If you have a file extension associated with a program the default behavior would be to open one instance for each file. If you want your program to open all of them you'd probably have to change your code a bit. <--- If I understood Jos's interpretation correctly.

Link to comment
Share on other sites

Don't think the people responded understand the question. :P

I get when I set the compiled script to run when "Open" is selected for my ".tst" extension the following:

My test script runs as many times as the number of files selected.

Using WinXP sp3

Jos

Right, that's the problem. How to solve this?

I want to open 2 files in one exe. not each file in an exe.

I select and open 2 files like this:

post-34381-1224145596_thumb.png

Link to comment
Share on other sites

  • Developers

I doubt this can be changed since this is an Explorer functions.

Do you need to do this from Explorer or could you also use the autoit3 build in FIles select option ?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I doubt this can be changed since this is an Explorer functions.

Do you need to do this from Explorer or could you also use the autoit3 build in FIles select option ?

Jos

I need to do this from the Explorer. How to change this in Explorer?

@j0linus: Thanks for reply. I can't explain it to the end users to use my program with the 'Send-To menu'.

Link to comment
Share on other sites

this depends on the program that opens the file

if you're using notepad++ (and make it the default for opening text), it has tabbed setting that can open simultaneous files in one .exe

just use shellexecute..

MsgBox(0,"Message","Script Started")

IF ubound($CmdLine)-1 > 0 Then

For $i = 1 to ubound($CmdLine) -1

ShellExecute($CmdLine[$i])

Next

EndIf

Link to comment
Share on other sites

  • Developers

I need to do this from the Explorer. How to change this in Explorer?

@j0linus: Thanks for reply. I can't explain it to the end users to use my program with the 'Send-To menu'.

As I said: To my knowledge its the way Explorer works...

only thing I could think of is that the script you write and is shelled by Explorer multiple times is monitoring for a short while for other instances and you let one of the instances receive all information of the other instances. ( just thinking out loud without having tested any of it :P )

this depends on the program that opens the file

if you're using notepad++ (and make it the default for opening text), it has tabbed setting that can open simultaneous files in one .exe

just use shellexecute..

Don't think you understand the challenge at hand.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

This is a quick and dirty example of what I was thinking of:

#NoTrayIcon
#include<file.au3>
#include<misc.au3>
;
If $CmdLine[0] = 0 then Exit
; Test for first instance
If _Singleton("MyTestScript",1) Then
; save Information to file
    For $i = 1 To $CmdLine[0]
        FileWriteLine(@tempdir & "\test.txt",$CmdLine[$i])
    Next
; wait for other instances to finish
    While 1
        $inst = ProcessList(@ScriptName)
        If $inst[0][0] < 2 Then ExitLoop
        sleep(10)
    WEnd
Else
; save Information to file
    Sleep(50)
    For $i = 1 To $CmdLine[0]
        FileWriteLine(@tempdir & "\test.txt",$CmdLine[$i])
    Next
    sleep(50)
    Exit
EndIf
; Read all received parameters
Global $cmdparams
_FileReadToArray(@tempdir & "\test.txt",$cmdparams)
For $x = 1 to $cmdparams[0]
        MsgBox(0,"Selected File",$cmdparams[$x])
Next
FileDelete(@tempdir & "\test.txt")
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Well, explorer calls the App for EACH application :P Sp you have to handle this on your own, e.g. with WM_DROPFILES

#include <Memory.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Global Const $RECEIVERGUID = FileGetShortName(@ScriptFullPath) & "d58c3e50-01b4-4a14-bfd4-d6f06fceb600"

Global Const $WM_DROPFILES = 0x233
Global Const $tagDRAGINFO = "UINT uSize;" & _ ;                 /* init with sizeof(DRAGINFO) */
        "int pt[2];" & _ ; POINT
        "int fND;" & _
        "int WIDE;" ; statt den nächsten beiden Linien
;~      "ptr   lpFileList;" & _ ; LPSTR ( UNICODE: LPWSTR )
;~      "DWORD grfKeyState;"

; by Prog@ndy 
; translated Delphi-Source from: http://www.delphipraxis.net/topic49148.html
Func DropFilesOnWnd($AWnd, $AFiles) ;aFiles as CRLF splitted list
    Local $LInfoStruct = DllStructCreate($tagDRAGINFO)
    Local $LInfo
    Local $LRes;: Boolean;
    Local $LHGlobal;: Cardinal;
    $LRes = False;
;~   if copy(AFiles, length(AFiles), 1) <> #0 then
    $AFiles = StringReplace($AFiles, @CRLF, Chr(0)) & Chr(0);
    $LHGlobal = _MemGlobalAlloc(DllStructGetSize($LInfoStruct) + StringLen($AFiles) + 1,BitOR($GMEM_SHARE, $GMEM_MOVEABLE, $GMEM_ZEROINIT));
    If $LHGlobal <> 0 Then
        $LInfo = _MemGlobalLock($LHGlobal);
        If $LInfo <> 0 Then
            $LInfoStruct = DllStructCreate($tagDRAGINFO, $LInfo)
            DllStructSetData($LInfoStruct, 1, DllStructGetSize($LInfoStruct))
            Local $temp = DllStructCreate("char[" & StringLen($AFiles)+1 & "]",$LInfo+DllStructGetSize($LInfoStruct))
            DllStructSetData($temp,1,$AFiles)
;~          DllStructSetData($LInfo, "lpFileList", DllStructGetPtr($temp))
            DllStructSetData($LInfoStruct, 2, 20000,1)
            DllStructSetData($LInfoStruct, 2, -1234,2)
            $temp = ""
            $LInfoStruct = ""
;~       Move(AFiles[1], PChar(Cardinal(LInfo) + LInfo.uSize)^, length(AFiles));
            _MemGlobalUnlock($LHGlobal);
            $LRes = _WinAPI_PostMessage($AWnd, $WM_DROPFILES, $LHGlobal, 0);
        EndIf
        If Not ($LRes) Then _
                _MemGlobalFree($LHGlobal);
    EndIf
;~   end;
    Return $LRes;
EndFunc   ;==>DropFilesOnWnd

Global $CMDLINEFILE = False
If $CMDLINE[0] >= 1 Then $CMDLINEFILE = $CMDLINE[1]
If $CMDLINEFILE And FileExists($CMDLINEFILE) Then
    If WinExists($RECEIVERGUID) Then
        $ret = DropFilesOnWnd(WinGetHandle($RECEIVERGUID), StringReplace($CMDLINEFILE, '"', ""))
        Exit
    Else
        ; nothing :)
    EndIf
EndIf
GUICreate($RECEIVERGUID, 1, 1, 0, 0) ; GUI to receive Dragdrop
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")


$title = "accept filename dropped on listview"
$GUI = GUICreate($title,-1,-1,-1,-1,-1,$WS_EX_ACCEPTFILES);
$ListView = GUICtrlCreateListView("file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |How was it added?",10,10,380,200)
GUISetState()
If $CMDLINEFILE Then GUICtrlCreateListViewItem($CMDLINEFILE&"|CMD-Line -firstone",$ListView)

while 1
    $msg = GUIGetMsg()

    if $msg = -3 then exit

WEnd

;Func copied from forum somewhere and modified
Func WM_DROPFILES($hWnd, $Msg, $wParam, $lParam)
    Local $tDrop, $aRet, $iCount
    ; POINT check :)
    Local $POINT = DllStructCreate("int[2]")
    DllCall("shell32.dll", "int", "DragQueryPoint", "hwnd", $wParam, "ptr", DllStructGetPtr($POINT))
;string buffer for file path
    $tDrop = DllStructCreate("char[260]")
;get file count
    $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "uint", -1, "ptr", DllStructGetPtr($tDrop), "int", DllStructGetSize($tDrop))
    $iCount = $aRet[0]
;get file paths
    Local $CurInfo = GUIGetCursorInfo($GUI)
    If (IsArray($CurInfo) And $CurInfo[4] = $ListView)  Then
        For $i = 0 To $iCount-1
            $aRet = DllCall("shell32.dll", "int", "DragQueryFile","hwnd", $wParam,"uint", $i,"ptr", DllStructGetPtr($tDrop),"int", DllStructGetSize($tDrop))
            GUICtrlCreateListViewItem(DllStructGetData($tDrop, 1)&"|DragDrop on LV",$ListView)
        Next
    ElseIf (DllStructGetData($POINT,1,1) = 20000 And DllStructGetData($POINT,1,2) = -1234 ) Then
        For $i = 0 To $iCount-1
            $aRet = DllCall("shell32.dll", "int", "DragQueryFile","hwnd", $wParam,"uint", $i,"ptr", DllStructGetPtr($tDrop),"int", DllStructGetSize($tDrop))
            GUICtrlCreateListViewItem(DllStructGetData($tDrop, 1)&"|CMD-Line",$ListView)
        Next
    EndIf
;finalize
    DllCall("shell32.dll", "int", "DragFinish", "hwnd", $wParam)
    Return
EndFunc

To try, compile and use a context menu entry like this:

HKCR\.testext\testentry\Command -> (Default) = "X:\PATH\TO\SCRIPT.exe" "%l"

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well, did my example help?

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...