Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2003, 03:58 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default validate file name..

hi all..

i need a function to validate the name of the file..

any pointers will be great..

thanks in advance...

Gonzalo Bianchi
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
Reply With Quote
  #2 (permalink)  
Old July 17th, 2003, 04:31 PM
Ned Ned is offline
Authorized User
 
Join Date: Jun 2003
Location: Toronto, ON, Canada.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gonzalo,
Tell me what kind of filename validatation you are looking for I mean DOS based (8 chars) or windows? You know there's a big difference.
-Ned

Quote:
quote:Originally posted by gbianchi
 hi all..

i need a function to validate the name of the file..

any pointers will be great..

thanks in advance...

Gonzalo Bianchi
Reply With Quote
  #3 (permalink)  
Old July 17th, 2003, 05:06 PM
Ned Ned is offline
Authorized User
 
Join Date: Jun 2003
Location: Toronto, ON, Canada.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gonzalo,
Here find the function that you looking for.
Cheers,
-Ned

'This function will check the validity of the filename.
Public Function ValidFileName(ByVal strFileName As String) As Boolean

    Dim bFound As Boolean

    On Error GoTo ValidFileName_Error

    ValidFileName = False 'Set default value

    If Trim(strFileName) <> "" Then
        'A valid filename cannot contain any of these characters /\:*?"<>
        bFound = InStr(1, strFileName, "/") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "\") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, ":") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "*") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "?") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, """") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "<") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, ">") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "|") > 0

        'Return validation status
        ValidFileName = Not bFound

    End If

Exit Function

ValidFileName_Error:
    'Abort if any errors occur
End Function


Quote:
quote:Originally posted by gbianchi
 hi all..

i need a function to validate the name of the file..

any pointers will be great..

thanks in advance...

Gonzalo Bianchi
Reply With Quote
  #4 (permalink)  
Old July 18th, 2003, 10:11 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

thanks ned.. i think that your function will do the trick..

just looking for win validation...



Gonzalo Bianchi
Reply With Quote
  #5 (permalink)  
Old July 18th, 2003, 12:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ned,
unfortunately you code covers only part of the naming convention rules
(see the "File Name Conventions" chapter in the file storage session of
the SDK manuals).
BTW there is an easier way to implement your if statements:

IsValid = not (sFileName like "*![/\\:*?""<>]*")

Marco

Quote:
quote:Originally posted by Ned
 Gonzalo,
Here find the function that you looking for.
Cheers,
-Ned

'This function will check the validity of the filename.
Public Function ValidFileName(ByVal strFileName As String) As Boolean

    Dim bFound As Boolean

    On Error GoTo ValidFileName_Error

    ValidFileName = False 'Set default value

    If Trim(strFileName) <> "" Then
        'A valid filename cannot contain any of these characters /\:*?"<>
        bFound = InStr(1, strFileName, "/") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "\") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, ":") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "*") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "?") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, """") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "<") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, ">") > 0
        If Not bFound Then _
            bFound = InStr(1, strFileName, "|") > 0

        'Return validation status
        ValidFileName = Not bFound

    End If

Exit Function

ValidFileName_Error:
    'Abort if any errors occur
End Function


Quote:
quote:Originally posted by gbianchi
 hi all..

i need a function to validate the name of the file..

any pointers will be great..

thanks in advance...

Gonzalo Bianchi
Reply With Quote
  #6 (permalink)  
Old July 18th, 2003, 12:55 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

marcos,

your code will not look for the * char in the string.. because the like will use it like a wildcard (will happend the same with ?)

anyway im on my way looking for the sdk.

thanks anyway...

Gonzalo Bianchi
Reply With Quote
  #7 (permalink)  
Old July 24th, 2003, 06:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Marco, I think that the line should be:

Code:
IsValid = Not (sFileName Like "*[/\:*?""<>]*")
I have just removed the ! from before the first square bracket, otherwise your code will always return True. I have also taken out the duplicate \ it is not needed because of the square brackets.

Gonzalo, the code will work because the square brackets state that what is between them are special characters and should not be treated as wildcards. The asterisks (*) before and after the square brackets are wildcards, but not the one in between.

The statement means "Like anything and any of these characters: / \ : * ? " < > followed by anything."

Regards
Owain Williams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
validate pdf arian29 Pro VB 6 0 November 27th, 2008 02:01 PM
How do I validate file upload? grstad Javascript How-To 30 March 10th, 2007 05:13 PM
How do I validate file input? grstad Classic ASP Professional 1 February 18th, 2007 08:45 PM
How to validate aspx file with xhtml 1.0 rishikantsinha .NET Framework 2.0 0 November 22nd, 2004 07:28 AM
Email Validate nskannan2007@yahoo.com HTML Code Clinic 3 June 9th, 2003 10:49 AM



All times are GMT -4. The time now is 08:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.