TazNormand a écrit:
Bon, il semblerait qu'on ne puisse pas obtenir le nombre de fichiers sélectionnés par OpenFileRequester()
la solution ( de Backupuser )
refaire le requester !!
les fichiers sont alors renvoyés séparé par le caractere "|" , il suffit de compter ce caractere a l'aide de countstring()+1
pour connaitre le nombre de fichier
code du openfileMultirequester()
Code:
; -----------------------------------------------------------------------------
; OpenMultiFileRequester ()
; -----------------------------------------------------------------------------
; A function to allow the calling of an OpenFileRequester that returns multiple
; files...
; WORK IN PROGRESS!!! Has a couple of bugs. See if you can tell why the alternative
; filter in the demo fails (at the bottom of this source), because I can't!
; [url]mailto:punkrockprogrammer@hi-toro.com">punkrockprogrammer@hi-toro.com
; -----------------------------------------------------------------------------
; NewLine ()
; -----------------------------------------------------------------------------
; Just returns a (Windows) newline/linefeed/whatever...
Procedure.s NewLine ()
ProcedureReturn Chr (13) + Chr (10)
EndProcedure
; -----------------------------------------------------------------------------
; OpenMultiFileRequester ()
; -----------------------------------------------------------------------------
; Returns a string containing the path of the selected files, followed by the
; names of the selected files. NOTE that all are separated by a "|" character!
; Example of returned string:
; "C:\My Documents|Pixies - Debaser.mp3|Pixies - Mr Grieves.mp3"
; That means the selected files were in "C:\My Documents", and the filenames
; were "Pixies - Debaser.mp3" and "Pixies - Mr Grieves.mp3"
; PARAMETERS...
; window -- the parent window. Use 0 if no window exists.
; title$ -- the text that appears in the requester's title bar ("Eg. Select files...").
; dir$ -- folder to start requester in (use "" for system default, usually "My Documents").
; filter$ -- a string defining a filter which says which files will be displayed (see below).
; maxfiles -- the routine has to pre-allocate memory for the filenames; it reserves the
; maximum filename length (#MAX_PATH) allowed by Windows, multiplied by this value.
; If you pass zero, it'll reserve enough for 1024 maximum-length filenames...
; flags -- the requester's flags. Use 0 for defaults, or -1 for literally no flags. You can
; specify your own flags as per the Win32 API docs if you know what you're doing!
; Returns "" (empty string) if it fails or user cancels...
Procedure.s OpenMultiFileRequester (window, title$, dir$, filter$, maxfiles, flags)
DefType.OPENFILENAME req
req\lStructSize = SizeOf (OPENFILENAME) ; Size of structure
req\hWndOwner = window ; Parent window
req\hInstance = #NULL ; Not needed
If maxfiles = 0
maxfiles = 1024 ; Default to 1024 * max filename length
EndIf
If flags = 0
req\Flags = #OFN_ALLOWMULTISELECT | #OFN_EXPLORER | #OFN_HIDEREADONLY ; Default 'quick-fix' flags
Else
If flags = -1
req\Flags = 0 ; If you really want no flags, use -1!
EndIf
EndIf
filter$ = filter$ + "||" ; Filter string has to end with 2 x #NULL
; Poke filter string into a memory block (have to do this to keep Chr (0) in the string!)...
If AllocateMemory (0, Len (filter$), 0)
memstart = MemoryID ()
For a = 0 To Len (filter$) - 1
a$ = Mid (filter$, a + 1, 1) ; String chars are numbered 1... x, so adding 1 to a here...
If a$ = "|"
a$ = Chr (0) ; Replace "|" with Chr (0)
EndIf
PokeB (memstart + a, Asc (a$))
Next
Else
ProcedureReturn ""
EndIf
req\lpstrFilter = MemoryID () ; Filter is in our allocated memory
req\lpstrCustomFilter = #NULL ; Not needed
req\nMaxCustFilter = #NULL ; Not needed
req\nFilterIndex = 0 ; Use default filter order
If AllocateMemory (1, (maxfiles * #MAX_PATH), 0) = #False
ProcedureReturn ""
EndIf
req\lpstrFile = MemoryID () ; Buffer for file string
req\nMaxFile = (maxfiles * #MAX_PATH) ; Buffer length
req\lpstrFileTitle = #NULL ; Not needed
req\nMaxFileTitle = #NULL ; Not needed
req\lpstrInitialDir = @dir$ ; Initial directory
req\lpstrTitle = @title$ ; Title of requester
If GetOpenFileName_ (req) ; OK, call the requester
For a = 0 To req\nFileOffset - 1 ; req\nFileOffset is first *file* in list
file$ = file$ + Chr (PeekB (req\lpstrFile + a)) ; Before that is the selected directory...
Next
file$ = file$ + "|"
byte = req\nFileOffset ; OK, get rest of files after directory
Repeat
b$ = Chr (PeekB (req\lpstrFile + byte)) ; Read the character
If b$ = "" ; If it's Chr (0), we check the next character
If Chr (PeekB (req\lpstrFile + byte + 1)) = "" ; If the next character is also Chr (0), we're done
gotall = #True
Else
file$ = file$ + "|" ; Nope, just one Chr (0), so we have a complete filename
EndIf
Else
file$ = file$ + b$ ; Not Chr (0), so we add it to the filename
EndIf
byte = byte + 1 ; Next byte in string...
Until gotall = #True Or byte = (maxfiles * #MAX_PATH) - 1
; Free our memory, because this might get called over and over again...
FreeMemory (0)
FreeMemory (1)
ProcedureReturn file$ ; We're done!
Else
ProcedureReturn "" ; User cancelled requester
EndIf
EndProcedure
; -----------------------------------------------------------------------------
; Demo
; -----------------------------------------------------------------------------
; NOTE that this demo just replaces the "|" characters in the returned string with
; newlines, so each filename gets a separate line in the requester :)
filter$ = "Text files|*.txt|Zip files|*.zip|All files|*.*" ; Weird -- Zips don't get shown this way round,
; plus it opens in source folder instead of default... :/
;filter$ = "Zip files|*.zip|Text files|*.txt|All files|*.*" ; This one works
getfile$ = OpenMultiFileRequester (0, "Select files to open...", "", filter$, 0, 0)
result$ = ReplaceString (getfile$, "|", NewLine ())
If result$
MessageRequester ("Path: " + path$, "Selected files..." + NewLine () + NewLine () + result$, 0)
EndIf