Sign in Join
Wiki copytemporary

Free disk space: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11It is not obvious how to get the free space, in a directory. Here is working code from the [[CudaText]] project.
22```
33uses SysUtils;
44
55 function AppDiskGetFreeSpace(const fn: string): Int64;
66 begin
77 {$ifdef linux}
88 //this crashes on FreeBSD 12 x64
99 exit(SysUtils.DiskFree(SysUtils.AddDisk(ExtractFileDir(fn))));
1010 {$endif}
1111
1212 {$ifdef windows}
1313 exit(SysUtils.DiskFree(SysUtils.GetDriveIDFromLetter(ExtractFileDrive(fn))));
1414 {$endif}
1515
1616 //cannot detect
1717 exit(-1);
1818 end;
1919```
2020
2121The "fn" parameter should be any filename in the needed directory. E.g. if we need to get free space in the directory '/home/user/media', pass parameter fn as '/home/user/media/a'.
2222
2323Note: code does not support Unixes other than Linux, because real tests show, that code for "$ifdef linux" part is crashing on FreeBSD 12 x64. Under FPC 3.2-fixes. [Gitlab issue](<https://gitlab.com/freepascal.org/fpc/source/-/issues/39428>).
2424
2525---
26-*From the Free Pascal wiki, page "Disk free space", as the Internet Archive kept it on 2024-08-15. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
26+*From the Free Pascal wiki, page "Disk free space", as the Internet Archive kept it on 2024-08-15, last changed on 2022-01-30. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history