Validating a filename Absolutepath lazarus / 61-Beginners ---------------------------------------------------------------------- JLWest · 2021-01-04 08:29 I have a edit entry and the users is required to enter either a name or an absolute path. Example: PhoneBook or F:\PhoneBook  if PhoneBook is entered I then test to make sure it doesn't already  exists and is a valid file name. ( Not Nil,  prt1, com1, ect). if good I create a directory on the  current drive/PhoneBook. such as C:\phonebook. No Problem. Is the a function/procedure to validate something like: K:\subdir\subdir2\PhoneBook so it will work on Win/Unix? Thanks ---------------------------------------------------------------------- ASerge · 2021-01-04 09:26 Quote from: JLWest on January 04, 2021, 09:29:00 amIs the a function/procedure to validate something like: K:\subdir\subdir2\PhoneBook so it will work on Win/Unix? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   FullPath := ExpandFileName(SomeText);  if not DirectoryExists(FullPath) then  CreateDir(FullPath); ---------------------------------------------------------------------- Warfley · 2021-01-04 13:38 Probably also check if there is no file with that name. Especially on Linux filenames without extensions are pretty common ---------------------------------------------------------------------- jamie · 2021-01-04 22:12 for persistence paths I use "ForceDirectories" it saves on the Boolean operation in place ---------------------------------------------------------------------- JLWest · 2021-01-05 01:06 I.m trying to write a file path validation function It works pretty good but it fails in two place. 1. Can't detect an invalid drive letter. 2. Fails when a directory already exists. Rules: User can enter a directory name or a full path. If directory name entered           program would create the directory on the same drive as the program is           installed. Only Characters and spaces allowed for a directory name. To Test this segment I created a directory x:\phonebook Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    {Just a Name entered}   if ( Simi = 0 ) and ( Slashes = 0 ) and ( BSlaches = 0 ) then begin      a := Copy(LOC,1,3);      {Loc = Application.Location; }      X := a + FileName;      S := FileName;    Found := FileExists(X);      // X        = 'X:\phonebook'      // Exployer =  X:\phonebook      if Found then begin         {Already exits}         ValidationMessages(8,FileName);         Result := False;         exit;      end;                {Created a directory on X:\phonebook}    Result := True;   { Returns true and should be false}    exit;   end; ---------------------------------------------------------------------- jamie · 2021-01-05 02:23 There are ready made functions that exists to help you.. ExtractFileDrive : Returns the Drive letter from the path supplied. ExtractFIleDir   : Returns just the directory portion of the string; ExtractFileEx :Returns the Extension of the file name.. ExtractRelativePath : That will give you the complete path of where you are currently residing . If you look at the help file for some of these you will see others. Btw, using "ForceDirectories" wil create the directories if they don't exist or if they do in either case it will return TRUE. There are cases where you find a path that exists but its not writable. using the LazFileUtils there is a function "IsDirectoryWriteable" etc ---------------------------------------------------------------------- JLWest · 2021-01-05 03:05 @Jamie Yea, I can see 2 that I could use. 1. ExtractFileDrive : Returns the Drive letter from the path supplied. 2. ExtractFIleDir    : Returns just the directory portion of the string. However, neither one of those are in fileutils,  r lazfileutils or utils or system ---------------------------------------------------------------------- speter · 2021-01-05 04:52 They are in sysutils (https://www.freepascal.org/docs- html/rtl/sysutils/extractfiledrive.html - look in the top-right corner). cheers S. ---------------------------------------------------------------------- JLWest · 2021-01-05 06:00 Thank You