Jump to content

get multiple files selected from the file explorer context menu


Recommended Posts

hi dears, i have a question please
am now working for an audio player for the blind users
and i added an option to open a file from the right click context menu.
but here there is a small problem, i hope that you can help me to find a solution for it.
the problem is as follow :
when i added the problem into the context menu it work with successfuly if the user select just one file.
but if the user selected more then one file, here the problem
a multiple sections of the program will open.
my question is :
how i can detect the multiple selection from the context menu?
i know that it so  hard, but i know also that you are harder than it
for that dears please try to give me an solution for that problem.
thanks in advance

Link to comment
Share on other sites

Post your script or a reproducer script that works similarly that demonstrates the issue you're having.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

here is a small example

local $files = ""
if ($cmdLine[0] > 0) then
for $i = 1 to $CMDLine[0]
switch $CMDLine[$i]
case "/play", "-play", "-files"
if not ($i+1 <= $CMDLine[0]) then $files = $CMDLine[$i+1] & "|"
endSwitch
next
if not ($files = "") then
$files = stringSplit($files, "|")
if not (@error) then
$files[0] -= 1
main()
else
exit
endIf
else
main()
endIf

Link to comment
Share on other sites

  • 3 weeks later...

@nacerbaaziz I will be glad to help you but you gonna have to help me first by doing 4 simple things.

1- Put your code into Scite and use Tidy to indent your code.  It is unreadable like the way you posted yours.

2- You gonna make a small script to show us what is the exact content of the array $CMDLine you are receiving when selecting multiple files from the File Explorer (use ConsoleWrite to do it)

3- Post the results of the console here along with the code of 1- and 2-

4- Lastly but very important DO NOT call me Dear.  I don't know you.

Link to comment
Share on other sites

good morning
i return back again

sir
@Nine
am sorry because i told you dear. but we are in arabia using it for respect
and about the array that i want it
so sirs , i hav making an audio player for the blind users, and i added the program into the file explorer context menu of the audio Files
in usually we are using
$CMDLine[$i]
to get the commands line Options
until here all things was good
but if the user selected multiple files here the problem
i tried to use
for $i = 1 to $CMDLine[0]
next
to get all commands Line
but i found that the windows explorer  Send each file alone to the program and multy sections of the program will opened
for that i can't find an way to get all selected files from the context menu
i do it internally by adding an button to open files
but i need the context menu, can any one guide  me to do that please
am waiting for your help

Link to comment
Share on other sites

@nacerbaaziz Man I will do that easy for you. 

Follow instruction from helpers or dont get help anymore . 

 

@Nine Is a pretty good skilled coder. He asked you 4 things. If you dont do them even me wont try to go further with you. 

 

@Nine This is what i got :! 

local $files = ""
   if ($cmdLine[0] > 0) then
      for $i = 1 to $CMDLine[0]
         switch $CMDLine[$i]
            case "/play", "-play", "-files"
               if not ($i+1 <= $CMDLine[0]) then $files = $CMDLine[$i+1] & "|"
         endSwitch
      next
      if not ($files = "") then
      $files = stringSplit($files, "|")
         if not (@error) then
            $files[0] -= 1
            main()
         else
            exit
         endIf
      else
         main()
      endIf

@nacerbaaziz

This code that you posted got errors. 

 

First thing : main() function is not here ./? 

Second : Your first condition is never ending. Missing EndIf Operator. 

Third thing : As @FrancescoDiMuro said you. You ask somthuing. You show somthing else.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

You can do it this way:

; Windows Explorer on XP, Vista, 7, 8
$hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
If Not $hExplorer Then Exit

; Shell object
$oShell = ObjCreate( "Shell.Application" )

; Find window
For $oWindow In $oShell.Windows()
  If $oWindow.HWND() = $hExplorer Then ExitLoop
Next

; Selected items
For $oItem In $oWindow.Document.SelectedItems()
  ConsoleWrite( $oItem.Path() & @CRLF )
Next

 

Link to comment
Share on other sites

hi sirs
here what i ded
it successfully worked
but here there is an problem
i couldn't know how to let's the script run the main program only ones
it run it more than one section
can any one help me please
here is the code
i tried to folow all what you ded, but am using the code="autoit3" and the /code to post my codes because the code dialog is not accessible with the screen reader
I apologize to you for that.
this file named
shell.exe
and it work is to get the selected files from context menu and send it to my program named easyAudioPlayer.exe
i hope you can help me

#NoTrayIcon
#RequireAdmin
#Region
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Comment=shell manager
#AutoIt3Wrapper_Res_Description=easy Audio Player shell manager
#AutoIt3Wrapper_Res_Fileversion=4.1.0.0
#AutoIt3Wrapper_Res_ProductVersion=4.1.0.0
#AutoIt3Wrapper_Res_LegalCopyright=copyright© 2019, by nacer baaziz
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_Field=Productname|easy audio player
#AutoIt3Wrapper_Res_Field=ProductVersiojn|4.0.0.0
#AutoIt3Wrapper_Res_Field=CompanyName|NBSoft
#AutoIt3Wrapper_Res_Field=InternalName|easy Audio Player
#AutoIt3Wrapper_Res_Field=OriginalFilename|shell.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/mo
#EndRegion
Local $FilesExt = "*.3gp;*.AAC;*.AIFF;*.AMR;*.avi;*.FLAC;*.IT;*.M4A;*.men;*.mid;*.MIDI;*.MO3;*.MOD;*.MP1;*.MP2;*.MP3;*.MP4;*.MTM;*.OGG;*.opus;*.S3M;*.TtA;*.UmX;*.WAV;*.WMA;*.wmv;*.wV;*.Xm"
Local $fullPath
    If $CMDLine[0] = 0 Then
    MsgBox(16, "error", "This application is an internal application." & @CRLF & _
            "Sorry you can not use it as a stand-alone application." & @CRLF & _
            "For more information please contact the developer :" & @CRLF & _
            "Mr. Nacer Baaziz.")
        Exit
ElseIf $cmdLine[0] > 1 Then
    MsgBox(16, "error", "This application is an internal application." & @CRLF & _
            "Sorry you can not use it as a stand-alone application." & @CRLF & _
            "For more information please contact the developer :" & @CRLF & _
            "Mr. Nacer Baaziz.")
    Exit
Else
    If Not (FileExists(@ScriptDir & "\EasyAudioPlayer.exe")) Then Exit
    Local $runingCheck = ProcessList(@ScriptName)
    If Not @error Then
        For $i = 1 To $runingCheck[0][0]
            Local $pathing = $runingCheck[$i][1]
            If Not ($pathing = @AutoItPID) Then
                Exit
            EndIf
        Next
    EndIf
    Local $hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]")
    If Not ($hExplorer) Then
        ShellExecute(@ScriptDir & "\EasyAudioPlayer.exe", $CmdLineRaw, @WorkingDir & "\")
        Exit
    Else
        Local $oShell = ObjCreate("Shell.Application")
        For $oWindow In $oShell.Windows()
            If $oWindow.HWND() = $hExplorer Then ExitLoop
        Next
        Local $iSelected = 0, $sSelected = "", $LastSelected = ""
        For $oItem In $oWindow.Document.SelectedItems()
            If ($iSelected > 0) Then
                If StringInStr($oItem.Path(), " ") Then
                    $sSelected &= '"' & $oItem.Path() & '"' & "|"
                Else
                    $sSelected &= $oItem.Path() & "|"
                EndIf
                $iSelected += 1
            Else
                If StringInStr($oItem.Path(), " ") Then
                    $LastSelected = '"' & $oItem.Path() & '"'
                Else
                    $LastSelected = $oItem.Path()
                EndIf
                $iSelected += 1
            EndIf
        Next
        If ($iSelected = 1) Then
            $sSelected = $LastSelected
            ShellExecute(@ScriptDir & "\EasyAudioPlayer.exe", "-play " & $sSelected, @WorkingDir & "\")
        ElseIf ($iSelected > 1) Then
            $sSelected &= $LastSelected
            ShellExecute(@ScriptDir & "\EasyAudioPlayer.exe", "-play " & $sSelected, @WorkingDir & "\")
        EndIf
    EndIf
EndIf
Exit


thanks in advanced

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

×
×
  • Create New...