Jump to content
Sign in to follow this  

Add quotes around file names after Drag & Drop

Recommended Posts

Hi Everyone,


I'm using the following script to get files via drag & drop which which works fine, I'm just having the file names display in a msgbox at the moment as they will be passed to another command-line program later.


#include <GUIConstantsEx.au3>
#include <GuiConstants.au3>
#include <FileConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIEx.au3>
#include <Array.au3>
#include <String.au3>

;Global Declaration
Global $aDrop_List, $__aGUIDropFiles, $dropFile, $Main

$Main = GUICreate("Main", 400, 400, -1, -1, $WS_POPUP, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x8a64e7, $Main)
GUICtrlCreateLabel("Drop files here", 45, 11, 240, 23, -1, -1)
GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI")
GUICtrlSetColor(-1, "0xFFFFFF")
GUICtrlSetBkColor(-1, "-2")

Local Const $iDrop = GUICtrlCreatePic("Image\image.jpg", 100, 60, 100, 100, -1, -1)

GUISetState(@SW_SHOW, $Main)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE


Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    Switch $iMsg
        Case $WM_DROPFILES
            Local Const $aReturn = _WinAPI_DragQueryFileEx($wParam)
            If UBound($aReturn) Then
                $__aGUIDropFiles = $aReturn
                Local Const $aError[1] = [0]
                $__aGUIDropFiles = $aError

Func _DropFunc()
    Local $String = _ArrayToString($__aGUIDropFiles, " ", 1, UBound($__aGUIDropFiles) - 1)

The problem is the command line program I'm using doesn't support spaces in the file names so can anyone help me wrap each file name in quotes once they have been dropped in, or after the _ArrayToString function I think would work.

I'm not even sure where to start with fixing this, The only thing I thought was to add quotes before and after the $string variable in the msgbox but this can only work if 1 file has been dropped in and not multiple files which is what I require.

Any help would be greatly appreciated.

Many Thanks


Share this post

Link to post
Share on other sites

Hi Guys,


Thanks for your suggestions, The second solution worked with a minor modification.

Local $String = StringReplace (_ArrayToString($__aGUIDropFiles, "|", 1),"|",'" "')

This now formats as follows which is exactly what I needed.

"File 1.txt" "File 2 - copy.jpg"


Many Thanks

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...