Generic file name validation code?

H

harry

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
 
R

Roedy Green

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.
 
H

harryajh

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");
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

harryajh said:
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
 
E

Eric Sosman

Arne said:
harryajh said:
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.
 
S

Stefan Ram

Roedy Green said:
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 »ram.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 =
"¿Aren't Kafka's Schloß and Æsops oeuvres often naïve?";

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 »Filode« 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
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top