Connecting Tech Pros Worldwide Forums | Help | Site Map

Generic file name validation code?

harry
Guest
 
Posts: n/a
#1: Sep 2 '07
I need to validate a file name but it has to work on Windows & Unix!

Does anybody know of java code that does this?

thanks in advance

harry



Robert Larsen
Guest
 
Posts: n/a
#2: Sep 3 '07

re: Generic file name validation code?


harry wrote:
Quote:
I need to validate a file name but it has to work on Windows & Unix!
>
Does anybody know of java code that does this?
>
thanks in advance
>
harry
>
>
This sounds easy to write using the java.util.regex package.
How should a file name look like ?
Mark Rafn
Guest
 
Posts: n/a
#3: Sep 3 '07

re: Generic file name validation code?


harry <a@abc.comwrote:
Quote:
>I need to validate a file name but it has to work on Windows & Unix!
What's "it" in that sentence? The code or the filename? It's very easy to
make the code work in multiple OSs, of course. It's very hard to make a
perfect validator to ensure that a filename would be valid in, say, the
Japanese release of Windows 95 when running under Solaris with an 8859-1
default encoding.
Quote:
>Does anybody know of java code that does this?
java.io.File forces some amount of well-formedness, and getCanonicalFile()
will normalize it using OS-specific code. If you try to actually create or
read the file, you'll be certain that the path is valid.

You won't know if it would be valid on another OS, but you really can't
know that anyway - different paths, drive letter conventions, permissions,
conflicting files, etc, even on the same OS on another machine will break.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
Closed Thread