Recent

Author Topic: how to get recycle bin size  (Read 4418 times)

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: how to get recycle bin size
« Reply #30 on: March 23, 2022, 04:09:44 pm »

Just bytes

719193658  bytes  time taken 640
719193787  bytes  time taken 2922
Press return to exit

first run omit hidden.
second run use all files.

Thanks for the offer of Geany help Thaddy.
I do have Lazarus in a folder, but I rarely use it.
I also use devpas ide sometimes, rarely, pointing to fpc 3.2.0, 64 bits.


 

 

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: how to get recycle bin size
« Reply #31 on: March 23, 2022, 04:19:32 pm »
Just bytes
719193658  bytes  time taken 640
719193787  bytes  time taken 2922
Press return to exit
first run omit hidden.
second run use all files.
Weird. When I get a moment I need to look at why my method returns +800MB for you and the dir method much much less.


BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: how to get recycle bin size
« Reply #32 on: March 23, 2022, 04:35:54 pm »

719193787/1024/1024 = 685.8766431808472 mb.
and my disk clean up says 685 mb. in the recycle bin.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: how to get recycle bin size
« Reply #33 on: March 23, 2022, 04:38:34 pm »
719193787/1024/1024 = 685.8766431808472 mb.
and my disk clean up says 685 mb. in the recycle bin.
Yes, and the ole method gave you 811,908,773 bytes so there must be something wrong with the counting there  :-X

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: how to get recycle bin size
« Reply #34 on: March 23, 2022, 09:41:31 pm »
The $RECYCLE.BIN is even more weird.
Mine was probably corrupted because it had files in it which where already purged from the bin and weren't even visible in the recycle bin.
And yes, that was for my profile directory.

The $RECYCLE.BIN also contains the recycle bin from other users. And you might not have access to it though your own account (only as administrator) with the dir method.

Another thing is that for each file that is deleted (it will be renamed to something like $Rxxxx) there is a $Ixxxx file with some extra original file information (where the file was, when it was deleted, etc). That file also takes some space and the OLE method doesn't include those.

@BobDog I still find it weird that the OLE method was bigger than your dir method because the dir method should have been larger because of the meta $I files. The only thing I kan think of is that the OLE method lists files on ALL drives and ALL profiles. You dir method only lists files (and $I meta) from the C: drive. Disk cleanup is also "per drive". Not for ALL drives. So maybe you have some deleted files on other volumes (which the OLE method included).

Even so... I wouldn't use the exec(dir) method but if I wanted to cycle through all the files I would just use the FindFirst/FindNext files api to go through them.

To summarize: The file iteration method is a better indication of the exact bytes (because the $I meta files are included and they take up space) but doesn't automatically take all drives. The OLE method counts real file-size of deleted files over all drives (so not meta) but is very slow with lots of files and less accurate when that count increases.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: how to get recycle bin size
« Reply #35 on: March 24, 2022, 12:28:18 am »

I only have one drive.
But anyway, thanks for your feedback on this, and I have accordingly changed my profile.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: how to get recycle bin size
« Reply #36 on: March 24, 2022, 05:19:11 pm »
(I need {$mode delphi} to use result)
Isn't the default ObjFPC in FPC? There Result should work too.
Or are you working with TP mode normally?
Orhas Geany ide another default?

The default mode of FPC itself is mode FPC, not ObjFPC. Lazarus usually overwrites that with its own settings.

jcmontherock

  • Full Member
  • ***
  • Posts: 236
Re: how to get recycle bin size
« Reply #37 on: March 24, 2022, 06:27:30 pm »
I am using the following:
Code: Pascal  [Select][+][-]
  1. ...
  2. TRecord = Record                               // offset   length
  3.   Header:   Int64;                               //   0        8
  4.   FileSize: Int64;                                 //   8        8
  5.   DelDate:  Array[0..7] of Byte;           //  16        8
  6.   FileLgth: Integer;                             //  24        4
  7.   Filename: Array[0..260] of WChar;  //  28        variable
  8. end;
  9. ...
  10. procedure TForm1.GetTrashFileProp(
  11.                 IFilename: String; Out RFilename: String; Out DelDate: TDateTime; Out iSize: Integer);
  12. var
  13.   DT: TDateTime;
  14. begin
  15.   fRecord := ReadFile(IFilename);
  16.   RFilename := UTF8Encode(UnicodeString(fRecord.Filename));
  17.   iSize := fRecord.FileSize;
  18.   DT := IncMilliSecond(encodedate(1601, 1, 1), UInt64(fRecord.DelDate) div 10000 );
  19.   DelDate := UniversalTimeToLocal(DT);
  20.   iSize   := fRecord.FileSize;
  21. End;
  22.  
  23. function TForm1.ReadFile(sInputFilePath: String): TRecord;
  24. var
  25.   fsInFile: TFileStream;
  26. begin
  27.   Result := Default(TRecord);
  28.   if FileExists(sInputFilePath) then begin
  29.     fsInFile := TFileStream.Create(sInputFilePath, fmOpenRead);
  30.     fsInFile.Position := 0;
  31.     fsInFile.ReadBuffer(Result, fsInFile.Size);
  32.     fsInFile.Free;
  33.   end
  34.   else ShowMessage('Error: cannot open file "' + sInputFilePath + '"');
  35. end;
  36.  

First you have to be sure that the i$ file is a file.
 
Then in GetTrashFileProp, IFilename is the $i file and RFilename is the real deleted file name.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018