Ross Levis wrote:
> Is there a Delphi (7) or Windows function which checks a potential
> filename for invalid filename characters and replaces invalid chars with
> some other char?

No. In part, it depends on which file system will receive the file.

> I have a simple function as follows:
>   for i := 1 to length(Result) do
>    if Result[i] in ['\','/',':',';','*','?','"','<','>','|','+','=']
> then
>     Result[i] := ' ';

I'm pretty sure "+" and "=" are allowed. Be careful that you trim leading
and trailing spaces. I think the shell trims them automatically, but I'm
not sure whether the kernel does, so you could inadvertantly generate file
names that Explorer or cmd.exe won't allow access to.

> But I suspect this will cause problems with unicode filenames.

That particular code won't work because you can't have a set of Unicode
characters. Other than that, I don't see any problems. NTFS supports
Unicode names. There are some characters that would be strange for a file
name to contain, such as the paragraph-break character or the zero-width
non-joiner, but I don't think the file system itself would object to
those. Again, it would probably be Explorer that has problems with those
sorts of characters.

> The filename is being constructed from information stored in a database
> which could contain unicode chars.

You could take the heavy-handed approach and convert all strings to ASCII.

-- 
Rob


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to