IonicWind Software

IWBasic => General Questions => Topic started by: TexasPete on February 03, 2009, 03:34:53 PM

Title: filter with findopen
Post by: TexasPete on February 03, 2009, 03:34:53 PM
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
Title: Re: filter with findopen
Post by: LarryMc on February 03, 2009, 03:49:22 PM
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
Title: Re: filter with findopen
Post by: fasecero on February 03, 2009, 04:36:40 PM
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

Title: Re: filter with findopen
Post by: Doc on February 03, 2009, 07:28:38 PM
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
Title: Re: filter with findopen
Post by: LarryMc on February 03, 2009, 08:18:03 PM
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
Title: Re: filter with findopen
Post by: aurelCB on February 04, 2009, 01:54:53 AM
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)