Sign in to follow this  
Followers 0
Kate

FileOpenDialog filter length limit

19 posts in this topic

Hello all,

I have the following code:

$sFileFilter = "$$A2BIOT*.RTF;$$A2EDEM*.RTF;ALPHA@DI*.RTF;$$A2RREA*.RTF;$$A2DCM2*.RTF;$$A2NUR#*.RTF;$$HFREAD*.RTF;$$PXEMA1*.RTF;$$PXNEON*.RTF;$$PXKOR3*.RTF;$$A2ABMC*.RTF;$$A2COS2*.RTF;OP@EXCEP*.RTF;OAMCOMB#*.RTF;$$PXFINO*.RTF;$$A2VCLS*.RTF;DML@ANAL*.RTF;$$PXIMRC*.RTF;$$PXOMRC*.RTF"
$pSource="\\mghsp4\archive\"&@YEAR&"\"&@MON&"\"&@MDAY&"\"

$rUserFile=FileOpenDialog("Please select a file or files",$pSource,"("&$sFileFilter&")",4)

However, the last file ($$PXOMRC) does not seem to show up in my dialog box (I double checked and the file does exist in the folder specified). Is there a limit to the number of characters you can have in the filter? If so, what is it and where is it documented? More importantly, if there is a limit, does anyone have any ideas for a workaround? I'd hate to go back to the drawing board on this particular part of my program :(

Thanks in advance!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

All your files starts from "$$", so you may use something like this:

$sFileFilter = "$$*.RTF"
$pSource="\\mghsp4\archive\"&@YEAR&"\"&@MON&"\"&@MDAY&"\"

$rUserFile=FileOpenDialog("Please select a file or files",$pSource,"("& $sFileFilter  &")",4)
Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If this is indeed a Windows or AutoIt restriction, then the first workaround I can think of is to use the simplified search string suggested by GS within a _FileListToArray() call. You could then process your specific filename strings against that array, deleting entries that you dont want, then load the array into a listview (possibly with checkboxes) and present that to the user? Probably better ideas will be offered to you shortly...

Edited by Spiff59

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Nope

Your example demonstrates it is not an issue regarding the length in bytes of the filter string.

I tried your code from a different perspective, the number of separate file types in the list, this test being far more than in the OP's example:

Func MAIN()
    If Not (FileExists('1') Or FileExists('2') Or FileExists('3')) Then
        FileWrite('1', '')
        FileWrite('2', '')
        FileWrite('3', '')
        Local $sFileFilter = '(1;A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;2;3)'
        Local $rUserFile = FileOpenDialog('FileOpenDialog', @ScriptDir, $sFileFilter)
        FileDelete('1')
        FileDelete('2')
        FileDelete('3')
    Else
        MsgBox(0, 'Message', 'Test FileName''s allready used.')
    EndIf
EndFunc
MAIN()

All 3 files were available in the list.

So, no problem with string length, or number of arguments, it appears FileOpenDialog() works just fine.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Wow, everyone, thanks for the extra brain power!

@GodlessSinner - I wish I could do that! Unfortunately, my files are sitting in a directory containing about 100 other files that start with "$$" - files which my script has nothing to do with.

@spiff59 and @mvgulik - thanks for coming up with a simulation of my situation. Using your simulations, and with a little luck, I was able to determine that both your examples work properly on my local computer but not the server on which the script runs. I am currently trying to establish the difference(s) between the two boxes that is causing the problem. Both the server and my computer have AutoIT v3.3.6.0 and SciTe version 1.79 so that wouldn't seem to be the problem. My next concern is that the server is running Windows Server 2003 and my computer is XP. I'm going to test and see if that's the problem right now.

I'll keep the board posted on what I find in case anyone else runs into this problem.

Thanks,

Kate

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

Well, I'm pretty sure we've got an OS issue here. I've done some testing using my own script and also mvgulik's and spiff59's and here's what I've observed:

My script DOES NOT work on Windows Server 2003 SP2, Windows Server 2003 R2 SP2 or Windows XP Service Pack 2. It DOES work on XP Service Pack 3 and Vista.

Furthermore, using mvgulik's script, I was able to confirm that what's happening on the older OS/Service Packs is that the OS is only paying attention to the first 260 characters of the filter. For example, on Server 2003, if you run mvgulik's script with the following filter (don't forget to include String.au3):

Local $sFileFilter = '(1;' & _StringRepeat("x",254) & ';2;3)'

That filter works. However, this filter does not:

Local $sFileFilter = '(1;' & _StringRepeat("x",255) & ';2;3)'

I believe this is the reason that spiff59's scripts work on all the OSes - the filter character length was short enough.

I guess it's down to coming up with a workaround :( Upgrading the OS of the VM that runs my script really isn't an option.

What my script does (if anyone was curious) is look at a directory on another server that has about 200 files in it, then present to the user 25 of those files to select for processing. One idea I thought of was copying all the applicable files to a temp directory - then my filter could be *.* I'm not sure I like that idea, though. I guess it's back to the drawing board.

Thanks everyone for your help! Problems are always easier when $NumberOfBrains>1

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

#include <GuiConstantsEx.au3>


#Include <File.au3>

$pSource="\\mghsp4\archive\"&@YEAR&"\"&@MON&"\"&@MDAY&"\"

$filter = "$$A2BIOT*.RTF;$$A2EDEM*.RTF;ALPHA@DI*.RTF;$$A2RREA*.RTF;$$A2DCM2*.RTF;$$A2NUR#*.RTF;$$HFREAD*.RTF;$$PXEMA1*.RTF;$$PXNEON*.RTF;$$PXKOR3*.RTF;$$A2ABMC*.RTF;$$A2COS2*.RTF;OP@EXCEP*.RTF;OAMCOMB#*.RTF;$$PXFINO*.RTF;$$A2VCLS*.RTF;DML@ANAL*.RTF;$$PXIMRC*.RTF;$$PXOMRC*.RTF"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 329, 464, 468, 299, BitOR($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$List1 = GUICtrlCreateList("", 16, 16, 297, 383, BitOR($LBS_SORT,$LBS_STANDARD,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER))

$Button1 = GUICtrlCreateButton("Select", 16, 416, 297, 33, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$FileList=_FileListToArray($pSource)

$split = StringSplit($filter, "*.RTF;")
For $i = 1 To $FileList[0] Step 1

    For $j = 1 To $split[0] Step 1
        If StringInStr($FileList[$i], $split[$j]) = 1  And  StringInStr($FileList[$i], ".RTF")  = StringLen($FileList[$i]) - 3  Then
            _GUICtrlListBox_AddFile($List1, $FileList[$i])
            ExitLoop;
        EndIf
    Next
Next


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0, "Current selected", _GUICtrlListBox_GetText($List1, _GUICtrlListBox_GetCurSel($List1)) )
    EndSwitch
WEnd

:(, but without multi-selection..

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

1) ? flag = 1, entire delimiter string is needed to mark the split

- I forgot

2) ? last "*.RTF;" has no trailing ";"

- because script checks a file and i don't think that filenames ends with ";" Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Its not that, the last file in the array maintains its "*.RTF" part because its not removed by the stringsplit. just a detail.

- Aa,
$filter = "$$A2BIOT*.RTF;$$A2EDEM*.RTF;ALPHA@DI*.RTF;$$A2RREA*.RTF;$$A2DCM2*.RTF;$$A2NUR#*.RTF;$$HFREAD*.RTF;$$PXEMA1*.RTF;$$PXNEON*.RTF;$$PXKOR3*.RTF;$$A2ABMC*.RTF;$$A2COS2*.RTF;OP@EXCEP*.RTF;OAMCOMB#*.RTF;$$PXFINO*.RTF;$$A2VCLS*.RTF;DML@ANAL*.RTF;$$PXIMRC*.RTF;$$PXOMRC*.RTF;"

- understood;)

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Argh!!!

This time I'm too slow!

I went this route (which may look like something in the 10 new posts I havent read since last in this thread...)

I create SearchMask.txt with two lines:

\\mghsp4\archive\

$$*.RTF

Then a FileMasks.txt with:

$$A2BIOT

$$A2EDEM

$$ALPHA@DI

$$A2RREA

$$A2DCM2

$$A2NUR#

$$HFREAD

$$PXEMA1

$$PXNEON

$$PXKOR3

$$A2ABMC

$$A2COS2

$$OP@EXCEP

$$OAMCOMB#

$$PXFINO

$$A2VCLS

$$DML@ANAL

$$PXIMRC

$$PXOMRC

And ran this against it (far from a polished final effort, but a proof of concept):

#include <array.au3>
#include <file.au3>
#include <ListviewConstants.au3>

$pSource = FileReadLine("Parms.txt", 1) ; load source path
;$pSource &= @YEAR & "\" & @MON & "\" & @MDAY
$sFileFilter = FileReadLine("Parms.txt", 2) ; load main search mask
$aFileList= _FileListToArray($pSource,$sFileFilter) ; load filelist
_ArrayDisplay($aFileList,"before") ; test

; load filename masks for include list
Dim $aIncludeList
_FileReadToArray("FileMasks.txt", $aIncludeList)
_ArrayDisplay($aIncludeList) ; test

; calculate string lengths for later compares
Dim $aIncludeListLen[$aIncludeList[0] + 1]
For $i = 1 to $aIncludeList[0]
    $aIncludeListLen[$i] = StringLen($aIncludeList[$i])
Next

; strip unwanted files from array
$i = 1
While $i <= $aFileList[0]
    $found = 0
    For $j = 1 to $aIncludeList[0]
        If StringLeft($aFileList[$i],$aIncludeListLen[$j]) = $aIncludeList[$j] Then
            $found = 1
            ExitLoop
        EndIf
    Next
    If $found Then
        $i += 1
    Else
        _ArrayDelete($aFileList, $i)
        $aFileList[0] -= 1
    EndIf
WEnd

_ArrayDisplay($aFileList,"after") ; test

; Build GUI and display array in ListView
GUICreate("", 160, 190)

$listview = GUICtrlCreateListView(" Select file(s) to process ", 10, 10, 140, 150, -1, $LVS_EX_CHECKBOXES)
For $i = 1 to $aFileList[0]
    $item1 = GUICtrlCreateListViewItem($aFileList[$i], $listview)
Next
$BTN_Select = GUICtrlCreateButton("SELECT", 50, 165, 60, 20)
GUISetState()

; Main loop
While 1
    If GUIGetMsg() = -3 Then ExitLoop
WEnd

Edit: It might be slicker to make the $pSource variable line 1 of a "parms.txt" file (replacing the SearchMask.txt) file, and then make the "$$*.RTF" string the second line of that new file. Then nothing would be hardcoded in the source.

Edit2: Ok, I applied the changes from my edit above... (and fixed a bug)

Edited by Spiff59

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Just a idea. you do not need to copy the files(data), only the names(empty files). same result, you get your filespecs.

Or perhaps you were thinking of FileCreateNTFSLink(). Make some alternative directories on the same volume partition which have hardlinks of certain filetypes which are linked to the main directory of interest. :(

Edit:

Added partition which means on same partition to be able to work correct.

Edited by MHz

Share this post


Link to post
Share on other sites

Kate,

It maybe easier to use a preselect option window as a workaround. It may make the selection process more friendly with more descriptions on the labels etc. :(

This example shows this, perhaps not the best but just an example.

#include <GuiConstants.au3>

; get filetypes to use
$filetypes = _Select_FileType_Gui()
If Not @error Then
    MsgBox(0x40000, 'You selected', $filetypes)
EndIf
FileOpenDialog('Select file to open', '', $filetypes)

Exit

Func _Select_FileType_Gui()
    Local $checkbox_accreports, $checkbox_arcreports, $checkbox_futreports
    Local $button_continue, $filetypes
    GUICreate('Select FileType', 300, 200)
    GUICtrlCreateLabel('Choose selection for File Open Dialog shown next', 20, 20)
    $checkbox_accreports = GUICtrlCreateCheckbox('Account Reports', 20, 50)
    $checkbox_futreports = GUICtrlCreateCheckbox('Future Reports', 20, 70)
    $checkbox_arcreports = GUICtrlCreateCheckbox('Archived Reports', 20, 90)
    $button_continue = GUICtrlCreateButton('&Continue', 120, 140)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case -3 ; window eXit clicked
                GUIDelete()
                $filetypes = 'All (*.*)'
                Return SetError(1, 0, $filetypes)
            Case $button_continue
                ; read checked selections
                If GUICtrlRead($checkbox_accreports) = $GUI_CHECKED Then
                    $filetypes &= '($$A2BIOT*.RTF);'
                EndIf
                If GUICtrlRead($checkbox_futreports) = $GUI_CHECKED Then
                    $filetypes &= '($$A2EDEM*.RTF);'
                EndIf
                If GUICtrlRead($checkbox_arcreports) = $GUI_CHECKED Then
                    $filetypes &= '(ALPHA@DI*.RTF);'
                EndIf
                GUIDelete()
                ; strip trailing ; char
                $filetypes = StringTrimRight($filetypes, 1)
                ; if not select, then use All (*.*)
                If Not $filetypes Then
                    $filetypes = 'All (*.*)'
                EndIf
                Return $filetypes
        EndSwitch
    WEnd
EndFunc

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Wow, you all are awesome <3 Thanks for the ideas! I decided to go the GUI route and I'm going to use a SQLite database table to store the path and file name of each applicable file. So, a record will get created in the table for each file that needs processing and then I can display the file list using a GUI w/ list view and checkboxes. I had been working on this concept before this whole filter length thing started because I wanted a way for the script to "remember" whether or not a specific file had already been processed. It didn't occur to me I could use that concept to solve my filter length problem until I saw some of y'all's ideas.

Thank you all again! :(

Kate

Edited by Kate

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  
Followers 0