Generic file name validation code?  
Author Message
harry





PostPosted: 2007-9-2 19:16:00 Top

java-programmer, Generic file name validation code? 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


 
harry





PostPosted: 2007-9-2 19:19:00 Top

java-programmer >> Generic file name validation code? 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


 
Roedy Green





PostPosted: 2007-9-2 19:40:00 Top

java-programmer >> Generic file name validation code? On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <email***@***.com> wrote, quoted or
indirectly quoted someone who said :

>
>Does anybody know of java code that does this?

If you limited the name to A-Z a-z 0-9 . it would work on anything
without a tight length limit anything.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
 
harryajh





PostPosted: 2007-9-2 19:57:00 Top

java-programmer >> Generic file name validation code? On 2 Sep, 12:40, Roedy Green <email***@***.com> wrote:
> On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <email***@***.com> wrote, quoted or
> indirectly quoted someone who said :
>
>
>
> >Does anybody know of java code that does this?
>
> If you limited the name to A-Z a-z 0-9 . it would work on anything
> without a tight length limit anything.
> --
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

Thanks Roedy, this seems to do the job (forgot to say file name must
end with "con")

Pattern p = Pattern.compile("([A-Z]|[a-z]|[0-9])+.con");

 
 
Arne Vajh鴍





PostPosted: 2007-9-2 22:14:00 Top

java-programmer >> Generic file name validation code? harryajh wrote:
> On 2 Sep, 12:40, Roedy Green <email***@***.com> wrote:
>> On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <email***@***.com> wrote, quoted or
>> indirectly quoted someone who said :
>>> Does anybody know of java code that does this?
>> If you limited the name to A-Z a-z 0-9 . it would work on anything
>> without a tight length limit anything.
>
> Thanks Roedy, this seems to do the job (forgot to say file name must
> end with "con")
>
> Pattern p = Pattern.compile("([A-Z]|[a-z]|[0-9])+.con");

That can be abbreviated to:

Pattern p = Pattern.compile("([A-Za-z0-9])+.con");

Arne


 
 
Eric Sosman





PostPosted: 2007-9-2 22:40:00 Top

java-programmer >> Generic file name validation code? Arne Vajh鴍 wrote:
> harryajh wrote:
>> On 2 Sep, 12:40, Roedy Green <email***@***.com> wrote:
>>> On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <email***@***.com> wrote,
>>> quoted or
>>> indirectly quoted someone who said :
>>>> Does anybody know of java code that does this?
>>> If you limited the name to A-Z a-z 0-9 . it would work on anything
>>> without a tight length limit anything.
>>
>> Thanks Roedy, this seems to do the job (forgot to say file name must
>> end with "con")
>>
> > Pattern p = Pattern.compile("([A-Z]|[a-z]|[0-9])+.con");
>
> That can be abbreviated to:
>
> Pattern p = Pattern.compile("([A-Za-z0-9])+.con");

Better quote that . character ... Also, the ( ) can be
eliminated if the O.P. doesn't need the capturing group.

--
Eric Sosman
email***@***.com
 
 
ram





PostPosted: 2007-9-3 2:58:00 Top

java-programmer >> Generic file name validation code? Roedy Green <email***@***.com> writes:
>On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <email***@***.com> wrote, quoted or
>indirectly quoted someone who said :
>>Does anybody know of java code that does this?
>If you limited the name to A-Z a-z 0-9 . it would work on anything
>without a tight length limit anything.

The library 籸am.jar?contains code to convert any
Unicode-Text (including surrogate pairs) into a text
consisting only of uppercase letters and numbers
that can be used as a file name under most
file systems as long as it is short enough.


public final class Main
{ public static void main( final String[] args )
{
final java.lang.String text =
"緼ren't Kafka's Schlo?and 苨ops oeuvres often na飗e?";

final java.lang.String product =
de.dclj.ram.notation.filode.Text.sourceText( text );

java.lang.System.out.println( product ); }}


XBFZYARENXNTXGYKAFKAXNSXGYSCHLOXDFZXGANDXGXC6ZSOPSXGOEUVRESXGOFTENXGNAXEFZVEXK


The encoding used is called 籉ilode?and being described
on the Filode homepage

http://www.purl.org/stefan_ram/pub/filode

The ram.jar homepage:

http://www.purl.org/stefan_ram/pub/ram-jar

 
 
Arne Vajh鴍





PostPosted: 2007-9-3 4:49:00 Top

java-programmer >> Generic file name validation code? Eric Sosman wrote:
> Arne Vajh鴍 wrote:
>> harryajh wrote:
>> > Pattern p = Pattern.compile("([A-Z]|[a-z]|[0-9])+.con");
>>
>> That can be abbreviated to:
>>
>> Pattern p = Pattern.compile("([A-Za-z0-9])+.con");
>
> Better quote that . character ...

Yes.

Arne
 
 
Robert Larsen





PostPosted: 2007-9-3 14:15:00 Top

java-programmer >> Generic file name validation code? harry wrote:
> 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 ?