Connecting Tech Pros Worldwide Help | Site Map

Function to validate a Unix file name?

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 25th, 2008, 01:45 PM
laredotornado
Guest
 
Posts: n/a
Default Function to validate a Unix file name?

Hi,

Can anyone provide a function that can validate if a string would pass
as a valid Unix (specifically Fedora Core 8 Linux) file name? For
example, I'm fairly certain one of the rules is that the file name
cannot contain a "&" character. There are probably a lot of other
rules I don't know about.

Thanks, - Dave

  #2  
Old August 25th, 2008, 03:15 PM
Joost Diepenmaat
Guest
 
Posts: n/a
Default Re: Function to validate a Unix file name?

laredotornado <laredotornado@zipmail.comwrites:
Quote:
Hi,
>
Can anyone provide a function that can validate if a string would pass
as a valid Unix (specifically Fedora Core 8 Linux) file name? For
example, I'm fairly certain one of the rules is that the file name
cannot contain a "&" character. There are probably a lot of other
rules I don't know about.
A unix file name may not contain a slash "/" or a null
character. There are no other limitations, except that many systems
have a maximum filename* length (255 chars seems to be the limit on
ext3).

* paths may be a lot longer since they can contain many filenames.


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
  #3  
Old August 26th, 2008, 08:55 AM
Bart Van der Donck
Guest
 
Posts: n/a
Default Re: Function to validate a Unix file name?

laredotornado wrote:
Quote:
Can anyone provide a function that can validate if a string would pass
as a valid Unix (specifically Fedora Core 8 Linux) file name? *For
example, I'm fairly certain one of the rules is that the file name
cannot contain a "&" character. *There are probably a lot of other
rules I don't know about.
I would play safe and allow alphanumeric + underscore + minus + dot.

--
Bart
  #4  
Old August 26th, 2008, 09:45 AM
virtuPIC
Guest
 
Posts: n/a
Default Re: Function to validate a Unix file name?

Well, as far as I know all characters except '/' (slash) and null are
allowed. Slash is the directory separator and null is end of string in
C implementation.

However, you should care about special use of certain characters in
shells. Like wildcards '*', '?'...

Also care for character set conversion. JavaScript uses Unicode but
Unix file names usually only use some ISO 8 bit representation which
is different from Unicode representation in many cases.

And regarding implementation of a checking function I recommend a
regular expression.

virtuPIC
--
Airspace V - international hangar flying!
http://www.airspace-v.com/ggadgets for tools & toys
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.