Please enable JavaScript to view this site.

Codolex

Navigation: Activities > File system

Path validations

Scroll Prev Top Next More

Path validations can be used to check on different parts if a path valid

uses System.IOUtils.TPath Methods

 

PathToValidate

Activity properties

 

begin

 var Variable: Boolean;

try

  var FileNamePart := TPath.GetFileName(PathToValidate);

  var PathPart := TPath.GetDirectoryName(PathToValidate);

   

  var IsValidFileName := TPath.HasValidFileNameChars(FileNamePart, False);

  var IsValidPathPart := TPath.HasValidPathChars(PathPart, False);

   

   Variable := IsValidPathPart and IsValidFileName;

except

  {$IF CompilerVersion > 34.0}

  on E: EInOutArgumentException do

  {$ELSE}

  on E: EArgumentException do

  {$ENDIF}

     Variable := False;

end;

end;

Resulting code

 

The option "Use wild cards" will enable the wildcards (*) and (?) in the given path/filename value

 

Available methods

 

Matches pattern

Has an extra string input for pattern

Returns True if the given value matches the specified pattern.

 

Example:

Path to validate = 'Project2024.fcp'.

Pattern to match = 'Project*.fcp'

 

begin

var Variable: Boolean;

 Variable := TPath.MatchesPattern(PathToValidate, 'Project*.fcp', False);

end;

Result = False

 

Drive exists

Checks whether the drive letter used in the given path actually exists.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\NonProject.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.DriveExists(PathToValidate);

end;

Result = False

 

Has Extension

Checks whether a given file name has an extension part.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.HasExtension(PathToValidate);

end;

Result = True

 

Has valid filename chars

Checks whether a given file name contains only allowed characters.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.HasValidFileNameChars(PathToValidate, False);

end;

Result = False

 

Has valid path chars

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.HasValidPathChars(PathToValidate, False);

end;

Result = True

 

Is drive rooted

Checks whether a given path is absolute and starts with a drive letter.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsDriveRooted(PathToValidate);

end;

Result = True

 

Is extended prefix

Checks whether a given path has an extended prefix. Extended meaning longer then the max path length of 260 chars.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsExtendedPrefixed(PathToValidate);

end;

Result = True

 

Is absolute path

Checks whether a given path is an absolute path .

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsPathRooted(PathToValidate);

end;

Result = True

 

Is relative path

Checks whether a given path is a relative path, in other words, not rooted to a drive.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsRelativePath(PathToValidate);

end;

Result = True

 

Is UNC path

Checks whether a given path is in UNC (Universal Naming Convention) format.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsUNCPath(PathToValidate);

end;

Result = False

 

is UNC rooted

Checks whether the given path is UNC-rooted, where UNC stands for Universal Naming Convention.

 

Example:

Path to validate = 'C:\Users\Username\Documents\Codolex\Project.fcp'.

 

begin

var Variable: Boolean;

 Variable := TPath.IsUNCRooted(PathToValidate);

end;

Result = False

 

Is valid filename chars

Checks whether a given character is allowed in a file name.

 

Example:

String to validate = 'C'.

 

begin

var Variable: Boolean;

 Variable := TPath.HasValidFileNameChars(PathToValidate[1]);

end;

Result = True

 

Is valid path chars

Checks whether a given character is allowed in a path string.

 

Example:

String to validate = 'C'.

 

begin

var Variable: Boolean;

 Variable := TPath.HasValidPathChars(PathToValidate[1]);

end;

Result = True

 

Is valid path

Checks whether a given value name contains only allowed characters for file and path.

Uses Has valid filename chars and Has valid path chars

 

Is valid and existing path

Checks whether a given value name contains only allowed characters for file and path, and if the path actually exists.

Uses Has valid filename chars and Has valid path chars plus Directory exists or File exists

© by GDK Software