Re: Making a string, file-safe (file-encode??)



adamorn@xxxxxxxxx wrote:
I was wondering if there was a quick way to ensure that a filename is
a safe.

What I mean is that if I am creating a file from a string variable, I
want to ensure that the file will actually be able to be created. So
if it contains a "?", then clearly I would want to eliminate it.

The "alphabets" for file names vary from system to system,
and there are systems on which '?' is perfectly legal. So your
"clearly" isn't really all that clear ...

In general, though, you can't guarantee that a file will
be creatable just by examining its name. On one widespread
system, "D:\\README.TXT" is a perfectly valid file name but you
are unlikely to succeed in creating a new file on a CD-ROM ...
Or you may lack permission to create files in some folders, or
the file system may be full, or ...

I know that there is something like URL encode that encodes strings
for use in urls, but is there another function that works similarly
for strings for files that I want to create?

I can't think of anything that deals with the problem of
different alphabets. File.separatorChar can help with some
of the syntax, or you can use the (File,String) constructor of
File. There's also a File constructor that takes a URI, but
that just seems to push the problem back a level without actually
solving it.

--
Eric.Sosman@xxxxxxx

.