Jump to content
Ian Branch

FaVolumeId??

Recommended Posts

Hi Team,

D11.2 patch 1, 32bit VCL Apps.

I have this bit of legacy code..

...
      //
      r := FindFirst(sTempFilesPath + '*.*', FaAnyfile, DirInfo); //  0 if files are found.
      //
      while r = 0 do
      begin
        if ((DirInfo.Attr and FaDirectory <> FaDirectory) and (DirInfo.Attr and FaVolumeId <> FaVolumeID)) then
          if DeleteFile(pChar(sTempFilesPath + DirInfo.Name)) = false then
            Memo1.Lines.Add('    Unable to delete file ' + sTempFilesPath + DirInfo.Name + '!')
          else
            Memo1.Lines.Add('    File ' + sTempFilesPath + DirInfo.Name + ' successfully deleted.');
        //
        r := FindNext(DirInfo);
        //
      end;
      //
...
...

D11.2 is telling me FaVolumeId is deprecated..

To what? 

What replaces it?

Alternatively, how should the above be now written?

Regards & TIA

Ian

Share this post


Link to post

I would rewrite this code using the routines from System.IOUtils. Use TDirectory.GetFiles to get a list of files in a directory you can then walk over.  TPath.GetTempPath gets you the user's temp folder, TFile.Delete deletes a file. Use a try except block around this statement to catch a failure to delete a file.

Share this post


Link to post

Hi Peter,

Tks for the pointer.  Haven't used those before.

I declared..

var
  Path: string;
  Filenames: TArray<string>;
  i: Integer;

Then coded..

    //
    Filenames := TDirectory.GetFiles(sTempFilesPath);
    //
    Memo1.Lines.Add('Now deleting ' + Length(Filenames).ToString + ' files found in the Database Temp Files Drive/Directory.');
    //
    for i := 0 to Length(Filenames) - 1 do
    begin
      if DeleteFile(PChar(sTempFilesPath + Filenames[i])) = False then
        Memo1.Lines.Add('    Unable to delete file ' + sTempFilesPath + Filenames[i] + '!')
      else
        Memo1.Lines.Add('    File ' + sTempFilesPath + Filenames[i] + ' successfully deleted.');
      //
      next;
    end;
      //
    Memo1.Lines.Add('The Database Temp Files Drive/Directory has been cleared.');
    Memo1.Lines.Add(' ');
      //

I used DeleteFile rather than TFile.Delete as the latter did not give me a boolean response for the Memo lines.

 

Regards,

Ian

Share this post


Link to post
7 hours ago, Ian Branch said:

Alternatively, how should the above be now written?

From the source:

 

faVolumeID    = $00000008 platform deprecated;  // not used in Win32

 

Looks like it was removed from windows.

Share this post


Link to post

Hi Team,

After further study it cleaned own to this..

  //
  // Delete all files in the Server Temp Files Path.
  //
  if Trim(sTempFilesPath) <> '' then
  begin
    //
    DBE1.Close;
    //
    aFilenames := TDirectory.GetFiles(sTempFilesPath);
    //
    Memo1.Lines.Add('Now deleting ' + Length(aFilenames).ToString + ' files found in the Database Temp Files Drive/Directory.');
    //
    for FileName in aFileNames do
    begin
      //
      if DeleteFile(FileName) = False then
        Memo1.Lines.Add('    Unable to delete file ' + FileName + '!')
      else
        Memo1.Lines.Add('    File ' + FileName + ' successfully deleted.');
      //
    end;
    //
    Memo1.Lines.Add('The Database Temp Files Drive/Directory has been cleared.');
    Memo1.Lines.Add(' ');
    //
  end;
  //

Tks to all.

 

Regards,

Ian

Edited by Ian Branch

Share this post


Link to post
if Trim(sTempFilesPath) <> '' then

Trim *returns* the trimmed string, it doesn't trim it in place. Your code is still working on the non-trimmed sTempFilesPath.

Share this post


Link to post

Hi Nigel,

Correct, the test is to ensure that sTempFilesPath actually has something in it.

I suppose I could just as easily have used sTempFilesPath.IsEmpty.

 

Ian

Share this post


Link to post
11 hours ago, Ian Branch said:

I suppose I could just as easily have used sTempFilesPath.IsEmpty.

Quote

Returns whether this 0-based string is empty (does not contain any characters).

IOW, that method won't save you from paths containing only spaces

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×