Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > how to check if file extension is member of filter list?

Reply
Thread Tools

how to check if file extension is member of filter list?

 
 
bart plessers
Guest
Posts: n/a
 
      07-27-2003
Hello,

I am developping a file browser bu use of internet explorer.

I am already so far that I get a full list of all the files of a selected
directory.
However, I only want to display certain files, i.e. pictures: jpg, gif, png,
tiff, etc...

So I want to set up a main variable, containing this "filter"

Now for every listed file, I want to check if its extension is listed in the
filter.

How can I achieve this without having an if-then for every extension?


tia

bartp




--

==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================






 
Reply With Quote
 
 
 
 
bart plessers
Guest
Posts: n/a
 
      07-27-2003
Yan,

that was what I was looking for!

will try it tomorrow. Maybe you can provide me with some sytax? How to build
the list? Is it just a string with all my extensions, separated by "," or
should I define some table?

tia

bartp

--

==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================





"yan Roosens" <> wrote in message
news:...
> Hello Bart,
>
> bart plessers wrote:
>
> > Hello,
> >
> > I am developping a file browser bu use of internet explorer.
> >
> > I am already so far that I get a full list of all the files of a

selected
> > directory.
> > However, I only want to display certain files, i.e. pictures: jpg, gif,

png,
> > tiff, etc...
> >
> > So I want to set up a main variable, containing this "filter"
> >
> > Now for every listed file, I want to check if its extension is listed in

the
> > filter.
> >
> > How can I achieve this without having an if-then for every extension?

>
> You could build a list of the extensions you want to display, with a

separator
> (a comma should do the trick) and use Instr(the list, the file extension)
>
> Yan
>
>
>
>



 
Reply With Quote
 
 
 
 
Tia
Guest
Posts: n/a
 
      07-28-2003

"bart plessers" <> wrote in message
news:...
> Hello,
>
> I am developping a file browser bu use of internet explorer.
>
> I am already so far that I get a full list of all the files of a selected
> directory.
> However, I only want to display certain files, i.e. pictures: jpg, gif, png,
> tiff, etc...
>
> So I want to set up a main variable, containing this "filter"
>
> Now for every listed file, I want to check if its extension is listed in the
> filter.
>
> How can I achieve this without having an if-then for every extension?
>



Hi,
here is my preferred method:


'-------------------------------------------

AllowedExtensions = Array("asp", "csv", "doc", "htm")


For i = 0 To UBound(FileList)
If IsFileNameOK(FileList(i)) Then ' your code here
Next


Function IsFileNameOK(strFileSpec) 'Boolean
' Find the dot
DotPos = InStrRev(strFileSpec, ".")
If DotPos > 0 Then
' get the extension
strExtension = LCase(Right(strFileSpec, Len(strFileSpec) - DotPos))
' Loop through allowable extensions
For i = 0 To UBound(AllowedExtensions)
' Check for a match
If strExtension = LCase(AllowedExtensions(i)) Then
IsFileNameOK = True
Exit For
End If
Next ' i
End If ' dot found
End Function


 
Reply With Quote
 
bart plessers
Guest
Posts: n/a
 
      07-28-2003
thanx for code and your time!
Tomorrow I'll be on holliday, but surely give it a try afterwards!

bartp

--

==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================





"Tia" <> wrote in message
news:bg1pt1$e0h$...
>
> "bart plessers" <> wrote in message
> news:...
> > Hello,
> >
> > I am developping a file browser bu use of internet explorer.
> >
> > I am already so far that I get a full list of all the files of a

selected
> > directory.
> > However, I only want to display certain files, i.e. pictures: jpg, gif,

png,
> > tiff, etc...
> >
> > So I want to set up a main variable, containing this "filter"
> >
> > Now for every listed file, I want to check if its extension is listed in

the
> > filter.
> >
> > How can I achieve this without having an if-then for every extension?
> >

>
>
> Hi,
> here is my preferred method:
>
>
> '-------------------------------------------
>
> AllowedExtensions = Array("asp", "csv", "doc", "htm")
>
>
> For i = 0 To UBound(FileList)
> If IsFileNameOK(FileList(i)) Then ' your code here
> Next
>
>
> Function IsFileNameOK(strFileSpec) 'Boolean
> ' Find the dot
> DotPos = InStrRev(strFileSpec, ".")
> If DotPos > 0 Then
> ' get the extension
> strExtension = LCase(Right(strFileSpec, Len(strFileSpec) - DotPos))
> ' Loop through allowable extensions
> For i = 0 To UBound(AllowedExtensions)
> ' Check for a match
> If strExtension = LCase(AllowedExtensions(i)) Then
> IsFileNameOK = True
> Exit For
> End If
> Next ' i
> End If ' dot found
> End Function
>
>



 
Reply With Quote
 
bart plessers
Guest
Posts: n/a
 
      07-28-2003
thanx for code and your time!
Tomorrow I'll be on holliday, but surely give it a try afterwards!

bartp

--

==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================





"Daniel Bush" <> wrote in message
news:...
> On Mon, 28 Jul 2003 01:39:31 +0200, "bart plessers"
> <> wrote:
>
> >Yan,
> >
> >that was what I was looking for!
> >
> >will try it tomorrow. Maybe you can provide me with some sytax? How to

build
> >the list? Is it just a string with all my extensions, separated by "," or
> >should I define some table?
> >
> >tia
> >
> >bartp

> here's something I whipped up. You should be able to modify it as
> necessary.
>
> function strDir(strPath)
> Dim fil,fol,arrExt,FSO,intCtr,strOut
> Set FSO = server.createobject("Scripting.FileSystemObject")
> arrExt = Array("gif", "jpg", "tif") ' put your extensions in here
> Set fol = FSO.GetFolder(strDir)
> strOut = vbNullString
> For Each fil In fol.Files
> For intCtr = LBound(arrExt) To UBound(arrExt)
> If StrComp(Mid(fil.ShortName, InStrRev(fil.ShortName, ".")
> + 1), arrExt(intCtr), 1) = 0 Then
> strOut = strOut & fil.Path & "<br>"
> End If
> Next
> Next
> set FSO=nothing
> strDir=strOut
> end function
> %>
>
> <html>
> <body>
> <p><%=strDir("c:\pictures")%></p>
> </body>
> </html>
>
>
> the function will return a string with <br> between the files. Of
> course, you can put whatever you want in there for syntax, like
> "<tr><td>" to return a HTML table, etc.
>
> Dan Bush
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
When does a binary extension gets the file extension '.pyd' and whenis it '.so' llothar Python 17 04-07-2008 02:54 AM
"rec.photo.digital.txt" Filter File Posted Online (for newsreadersthat can import a list of e-mail addresses to filter out) SMS 斯蒂文• 夏 Digital Photography 2 11-25-2007 11:00 AM
How to convert a .txt file extension to a .xls file extension? Steve ASP .Net 3 08-25-2006 05:43 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57