Jump to content

Help using _WinAPI_GetOpenFileName()


Go to solution Solved by BrewManNH,

Recommended Posts

I'm using _WinAPI_GetOpenFileName with $OFN_ALLOWMULTISELECT to first display a list of files in a GUICtrlCreateEdit box, then write the results to a text file.  The issue that I'm having is that the output looks like this:

C:test1
file1.txt
file2.txt
file3.txt
C:test2
filea.txt
fileb.txt
 

I would like it to be more like this:

C:test1file1.txt

C:test1file2.txt

C:test1file3.txt

C:test2filea.txt

C:test2fileb.txt

I've already reviewed _WinAPI_GetOpenFileName and $tagOPENFILENAME and couldn't find what I was looking for (unless I missed something).  Any recommendations on how to go about this?  Thanks!

Link to comment
Share on other sites

Post your code, otherwise we're guessing what you're doing.

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

Sorry about that.  I started with the example on the _WinAPI_GetOpenFileName() page - specifically with the _Example_ExplorerStyleMultiSelect() function since there were several example functions.  I tried several different flags (with no success) so I reverted back to the code from the example while I look into it further.

#include <StructureConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $iMemo

_Example_ExplorerStyleMultiSelect()

Func _Example_ExplorerStyleMultiSelect()
    Local $hGui, $btn_dialog, $aFile, $sError

    ; Create GUI
    $hGui = GUICreate("GetOpenFileName use Explorer Style (Multi Select)", 400, 296)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    $btn_dialog = GUICtrlCreateButton("Open Dialog", 155, 270, 90, 20)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $btn_dialog
                $aFile = _WinAPI_GetOpenFileName("My Open File Dialog", _
                        "Text File (*.txt;*.au3)", ".", @ScriptName, "", 1, _
                        BitOR($OFN_ALLOWMULTISELECT, $OFN_EXPLORER), 0, $hGui)
                If $aFile[0] = 0 Then
                    $sError = _WinAPI_CommDlgExtendedError()
                    MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
                Else
                    For $x = 1 To $aFile[0]
                        MemoWrite($aFile[$x])
                    Next
                EndIf
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGui)
EndFunc   ;==>_Example_ExplorerStyleMultiSelect


; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
Link to comment
Share on other sites

  • Solution

Change this section:
 

For $x = 2 To $aFile[0] ; <<<<<<<<<<<<<<<<<<<<<<< Change 1 to 2
    MemoWrite($aFile[1] & "\" & $aFile[$x]) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Append $aFile[1], which holds the folder name, to the file names
Next

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

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...