Connecting Tech Pros Worldwide Help | Site Map

Function to validate a Unix file name?

  #1  
Old August 25th, 2008, 02:45 PM
laredotornado
Guest
 
Posts: n/a
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, 04:15 PM
Joost Diepenmaat
Guest
 
Posts: n/a

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, 09:55 AM
Bart Van der Donck
Guest
 
Posts: n/a

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, 10:45 AM
virtuPIC
Guest
 
Posts: n/a

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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
gets() is dead jacob navia answers 280 May 24th, 2007 12:35 PM
Sequential Number in an Update eric.nave@gmail.com answers 19 November 2nd, 2006 11:35 PM
Can't make this page work scottyman@comcast.net answers 6 March 9th, 2006 04:25 AM
How to backup and restore from tape device nek answers 8 November 12th, 2005 09:24 AM