Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to validate a filename?

I figured this has to be in the RTL somewhere, but I looked and I can't find it.

function IsValidFilename(filename: string): boolean;
//returns True if it would be possible to create or open a file with
//this name, without modifying the current directory structure

In other words, it has to point to an existing folder on a valid local or network drive, and not contain any invalid characters. Do we have anything like that? (Bonus points if it checks the current user's access rights to be sure you can get at the folder in question.)

like image 499
Mason Wheeler Avatar asked Sep 23 '10 23:09

Mason Wheeler


People also ask

What is a file validator?

The File Validation Agent solution determines whether the files associated with documents in a workspace are missing. It searches for those files on a file server. It sets the value of a Yes/No field called the missing files indicator field. The value in this field indicates whether the files were found.

What file names are valid?

Supported characters for a file name are letters, numbers, spaces, and ( ) _ - , . *Please note file names should be limited to 100 characters. Characters that are NOT supported include, but are not limited to: @ $ % & \ / : * ?


1 Answers

So, this question is a bit old but in case you're looking: With XE and newer you can use the TPath class in System.IOUtils.

Result := TPath.HasValidFileNameChars(AFileName, UseWildcards); 
like image 173
Jessie Avatar answered Oct 06 '22 19:10

Jessie