Free disk space: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | It is not obvious how to get the free space, in a directory. Here is working code from the [[CudaText]] project. | |
| 2 | 2 | ``` | |
| 3 | 3 | uses SysUtils; | |
| 4 | 4 | ||
| 5 | 5 | function AppDiskGetFreeSpace(const fn: string): Int64; | |
| 6 | 6 | begin | |
| 7 | 7 | {$ifdef linux} | |
| 8 | 8 | //this crashes on FreeBSD 12 x64 | |
| 9 | 9 | exit(SysUtils.DiskFree(SysUtils.AddDisk(ExtractFileDir(fn)))); | |
| 10 | 10 | {$endif} | |
| 11 | 11 | ||
| 12 | 12 | {$ifdef windows} | |
| 13 | 13 | exit(SysUtils.DiskFree(SysUtils.GetDriveIDFromLetter(ExtractFileDrive(fn)))); | |
| 14 | 14 | {$endif} | |
| 15 | 15 | ||
| 16 | 16 | //cannot detect | |
| 17 | 17 | exit(-1); | |
| 18 | 18 | end; | |
| 19 | 19 | ``` | |
| 20 | 20 | ||
| 21 | 21 | The "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'. | |
| 22 | 22 | ||
| 23 | 23 | Note: 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>). | |
| 24 | 24 | ||
| 25 | 25 | --- | |
| 26 | - | ||
| 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).* |
