User Tools

Site Tools


selecting_20multiple_20files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

selecting_20multiple_20files [2018/03/31 13:19]
127.0.0.1 external edit
selecting_20multiple_20files [2018/04/15 17:27] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Selecting multiple files===== =====Selecting multiple files=====
  
-//by Richard Russell, March 2010//\\ \\  The main [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​opensave|Help documentation]] describes how to use the Windows **GetOpenFileName** common dialogue to select a file (usually so it can subsequently be opened). That dialogue also permits the selection of **multiple files** (using the optional **OFN_ALLOWMULTISELECT** flag), but the format in which the filenames and paths are returned is quite tricky to deal with. The format also differs according to whether only one file, or multiple files, are selected.\\ \\  The function listed below makes the selection of multiple files straightforward. It takes as parameters the **title** of the dialogue box, a file **filter** string and a string **array** in which to return the selected file(s); the function returns the number of files selected (or zero if the user clicked Cancel). The filter string contains the description(s) and extension(s) of the file types from which the user can make a selection. The array must be created before the function is called, and be sufficiently large to contain the maximum number of files that need to be selected; the first filename is returned in index 1 (not 0) of the array. An example of calling the function is as follows:\\ +//by Richard Russell, March 2010//\\ \\  The main [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwine.html#​opensave|Help documentation]] describes how to use the Windows **GetOpenFileName** common dialogue to select a file (usually so it can subsequently be opened). That dialogue also permits the selection of **multiple files** (using the optional **OFN_ALLOWMULTISELECT** flag), but the format in which the filenames and paths are returned is quite tricky to deal with. The format also differs according to whether only one file, or multiple files, are selected.\\ \\  The function listed below makes the selection of multiple files straightforward. It takes as parameters the **title** of the dialogue box, a file **filter** string and a string **array** in which to return the selected file(s); the function returns the number of files selected (or zero if the user clicked Cancel). The filter string contains the description(s) and extension(s) of the file types from which the user can make a selection. The array must be created before the function is called, and be sufficiently large to contain the maximum number of files that need to be selected; the first filename is returned in index 1 (not 0) of the array. An example of calling the function is as follows: 
 + 
 +<code bb4w> ​
         DIM files$(100)         DIM files$(100)
         filter$ = "All files"​+CHR$(0)+"​*.*"​         filter$ = "All files"​+CHR$(0)+"​*.*"​
Line 10: Line 12:
           NEXT           NEXT
         ENDIF         ENDIF
-If you want to sort the returned filenames into ascending alphabetical order you can easily do that using the SORTLIB library:\\ +</​code>​ 
 + 
 +If you want to sort the returned filenames into ascending alphabetical order you can easily do that using the SORTLIB library: 
 + 
 +<code bb4w>
         INSTALL @lib$+"​SORTLIB"​         INSTALL @lib$+"​SORTLIB"​
         sort% = FN_sortinit(0,​0)         sort% = FN_sortinit(0,​0)
         C% = num%         C% = num%
         CALL sort%, files$(1)         CALL sort%, files$(1)
-Here is the function itself:\\ +</​code>​ 
 + 
 +Here is the function itself: 
 + 
 +<code bb4w>
         DEF FNselectfiles(title$,​ filter$, file$())         DEF FNselectfiles(title$,​ filter$, file$())
         LOCAL fs{}, fp%, res%, nfiles%, P%, J%         LOCAL fs{}, fp%, res%, nfiles%, P%, J%
Line 54: Line 64:
         ENDIF         ENDIF
         =nfiles%         =nfiles%
 +</​code>​
 +
 The maximum number of files which may be returned is limited by the size of the supplied array, and by the total size of all the filenames not exceeding 65535 bytes. The maximum number of files which may be returned is limited by the size of the supplied array, and by the total size of all the filenames not exceeding 65535 bytes.
selecting_20multiple_20files.txt · Last modified: 2018/04/15 17:27 by richardrussell