May 09, 2024, 04:58:02 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


filter with findopen

Started by TexasPete, February 03, 2009, 03:34:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TexasPete

While reading a directory with findopen. by the way I searched for every example using find open on the site.

Anyway, I would like to include two types of files  to be included in a directory search. Would the following be correct? Didn't work for me.

filter$"(*.html ;*.txt")"

Bear in mind I am not using Filerequest. Only find open the filter would be attached to the end of the pathstring.
Thanks Texas Pete

LarryMc

Quote from: TexasPete on February 03, 2009, 03:34:53 PM
filter$"(*.html ;*.txt")"
That isn't a valid syntax any way you look at it.

I don't know what gave you the idea that you could take one command and merge parts you like from another command. ;)

I can't find anything in the documentation that even hints at it.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

filter$ if the wildcard of findopen? :)
In that case, I don't know if there is some way to use more than one wildcard in findopen, but maybe work if you look for all the files and then you filter what you need:


OPENCONSOLE
DEF dir:UINT
DEF filename:STRING
DEF file_ext:STRING

dir = FINDOPEN("c:\\*.*")

IF(dir)
    DO
        filename = FINDNEXT(dir)
file_ext=RIGHT$(filename,3)
IF file_ext="TXT" OR file_ext="txt" THEN
' filename contain txt file
PRINT filename
ENDIF
IF file_ext="HTM" OR file_ext="htm" THEN
' filename contain html file
PRINT filename
ENDIF
   UNTIL filename = ""
    FINDCLOSE dir
ENDIF

PRINT "Press Any Key"
DO:UNTIL INKEY$ <> ""

CLOSECONSOLE
END


Doc

February 03, 2009, 07:28:38 PM #3 Last Edit: February 03, 2009, 07:36:34 PM by Doc
Here ya go, TP
...a complete sub (slightly modified from one of the sample files)

SUB doopen

filter = "HTML or Text Files (*.htm *.html *.txt)|*.htm;*.html;*.txt|All Files (*.*)|*.*||"
filename = filerequest("File Open",win,1,filter,"txt")
if(len(filename) > 0)
buffer = ""
if( openfile(file1,filename,"R") = 0)
do
if(read(file1,ln) = 0)
if len(buffer) < (32766-257)
buffer = buffer + ln + chr$(13) + chr$(10)
endif
endif
until eof(file1)
closefile file1
setcontroltext win,1,buffer
endif
endif
RETURN
endsub


That should do it for ya.
Good luck,

-Doc-

Edit: Oooophs! I just re-read the post to see that you aren't using filerequest
Back to the drawing board, I guess

LarryMc

I'd do 2 interations:

One with
dir = FINDOPEN("c:\\*.htm*")  :'which will catch .htm and .html files

and then one with
dir = FINDOPEN("c:\\*.txt")

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Maby this will help:
'LINKER to current folder
Declare "kernel32",GetCurrentDirectoryA(nBufferLength:int,lpBuffer:String),int
'Get directory name with dirsize=255(API function)
GetCurrentDirectoryA(255,dirname)

dir=FINDOPEN(dirname+"\*.abp|*.txt") 

IF dir
filename = FINDNEXT(dir)
FINDCLOSE dir
Endif
'----LOADER--------------------------------------------
'//loader from editmulti control
if(len(filename) > 0 )
buffer = ""
if(OPENFILE(file1,filename,"R")=0)