Function to validate a Unix file name?

L

laredotornado

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
 
J

Joost Diepenmaat

laredotornado said:
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.
 
B

Bart Van der Donck

laredotornado said:
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.
 
V

virtuPIC

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top