CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    26

    Validate filename

    Does anyone knows how to know if a string is a valid Windows long file name?

    In other words, I need to know which ascii values out of the the (255) ASCII code characers are valid in a windows long filename.




  2. #2
    Join Date
    Nov 1999
    Posts
    18

    Re: Validate filename

    Assuming you do not need to add the extra complication of the path along with the filename, you can test out each character to see if it is NOT a valid character. This is easier than seeing if it IS valid. VB has a list of ASCII codes built into the help file - if you search for character codes or something like that you should find it. File names cannot include any of the following characters: forward slash (/), backslash (\), greater than sign (&gt, less than sign (&lt, asterisk (*), period (.), question mark (?), quotation mark ("), pipe symbol (|), colon (, or semicolon (. Just for your convienience - here is a list of ASCII codes which are NOT allowed in Windows long filenames...I think I've got them all right:

    34 Quotation mark
    42 Asterisk
    46 Period
    47 Slash
    58 Colon
    59 Semicolon
    60,62 Greater than, less than symbols
    63 Question mark
    92 Slash
    124 Pipe

    After checking the characters in the filename, you can then check that it does not exceed 255 chars:


    if len(Variable) >= 255 then
    'invalid
    else
    'valid
    end if




    This is just one way to do it. Another way would be to try and save the file to disk first, but set up an error trap and assign the function a return variable. By seeing if the returned value is success/failure, you can determine whether or not the file name is valid.

    Regards,
    psiclone.


  3. #3
    Join Date
    Aug 1999
    Posts
    7

    Re: Validate filename

    psiclone,
    Hi, just wondering how to test each character in a name or string to see if value is valid or not.

    something like this:

    string = "j-manning"
    I want to be able to look at each character in this string and determine if it fits my criteria for being valid. Valid codes are 48-57, 65-90, 97 -122, 45, 46, 95.

    Any help or direction would be appreciated greatly. Thx Harold


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured