Get Free space of Disk or USB lazarus / 34-Windows ---------------------------------------------------------------------- eldonfsr · 2022-05-21 23:49 How i can get free space  of usb or any disk on windows DiskFree(0) is current disk how i can ask for disk F or H ---------------------------------------------------------------------- trev · 2022-05-22 00:21 Please see the FPC documentation for diskfree for how to do this. ---------------------------------------------------------------------- eldonfsr · 2022-05-23 21:24 thanks trev  i read and tested but don't accept send string parameters only numbers how i can know what is number for hdd H, on linux sad use adddisk() but on windows is not available... . ---------------------------------------------------------------------- winni · 2022-05-23 22:23 Hi! 0 = current drive. 1 = A: 2 = B: 3 = C: 4 = D: 5 = E: .... Winni ---------------------------------------------------------------------- mas steindorff · 2022-05-23 23:25 that works if you know that you are after  D: or E: GetDiskFreeSpace() takes the drive as a string (cast to pchar) and returns lots of info you may find useful. you can use getDriveType() to find out if it is ...   TDrvType = (dtNotDetermined, dtNonExistent, dtRemoveable,               dtFixed, dtRemote, dtCDROM, dtRamDrive); and you can use GetVolumeInformation() to get the volume name use full if you named your USB drive and it is one of several pulled into the system. It's been a while since I worked on my "diskutil" unit but I believe they are all built ins. my uses ...   windows   ,fileutil   ,process   ,jwadbt   ;  incase you can not find something. ---------------------------------------------------------------------- eldonfsr · 2022-05-24 02:00 Thanks well some confuse  i send DiskFree(0) witch is current drive and return this value (0)   FSpaceD = -229756928 i chanege Diskfree(3) suppost is drive c:\ and return this value (3)   FSpaceD = -194945024 not must be same... could be partitions of HDD you can see on image values from windows 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 procedure TFormMain.BtnStartClick(Sender: TObject);var  FilesBkp: TStringList;  i:integer;  f: File of byte;  tbk,udisk:integer;  Info : TSearchRec;  Attributes: Integer;  CFolder,cFile,TDisk:String;  FSpace,FSpaceD:longint;  Disklt:Array[0..24]of String;begin  Attributes := Attributes or faHidden;  LogFile:= TMemo.Create(nil);  FilesBkp := TStringList.Create;  tbk:=0;  Disklt[1]:='A:\';  Disklt[2]:='B:\';  Disklt[3]:='C:\';  Disklt[4]:='E:\';  Disklt[5]:='F:\';  Disklt[6]:='G:\';  Disklt[7]:='H:\';  Disklt[8]:='I:\';  Disklt[9]:='J:\';  Disklt[10]:='K:\';  Disklt[11]:='L:\';  Disklt[12]:='M:\';  Disklt[13]:='N:\';  Disklt[14]:='O:\';  Disklt[15]:='P:\';  Disklt[16]:='Q:\';  Disklt[17]:='R:\';  Disklt[18]:='S:\';  Disklt[19]:='T:\';  Disklt[20]:='U:\';  Disklt[21]:='V:\';  Disklt[22]:='X:\';  Disklt[23]:='Y:\';  Disklt[24]:='Z:\';  try    if( ETFolder.Text<>'') then begin    for i:=0 to LbFolders.Items.Count-1 do  begin      FindAllFiles(FilesBkp, LbFolders.Items[i] , '*.*', true); //find e.g. all pascal sourcefiles    end; //   ShowMessage(Format('Files for backup %d ', [Filesbkp.Count]));    For i:=0 to FilesBkp.Count -1 do begin      AssignFile(f, FilesBkp[i]);//       LBFiles.Items.Add(FilesBkp[i]);      Reset(f);      tbk:=tbk+FileSize(f);      CloseFile(f)    end;    if( LbFiles.Items.Count > 0 ) then begin      for i:=0 to LbFiles.Items.Count-1 do  begin        AssignFile(f,LbFiles.Items[i]);        Reset(f);        tbk:=tbk+FileSize(f);        CloseFile(f)      end;    end;    StatusBar1.Panels[0].Text:='Total space required for Backup: '+ FloatToStr(tbk div (1024*1024))+' MB';    TDisk:=UpperCase( Copy(ETFolder.Text, 0, Pos('\',ETFolder.Text)));    for i:=0 to length(DiskLt) do begin       if( DiskLt[i] = TDisk ) then begin       udisk:=i;         break;       end;    end;    FSpaceD:=DiskFree(udisk);    FSpace:= FSpaceD div (1024*1024) ; // Mega Bit    If Not DirectoryExists(ETFolder.Text) then begin       If Not CreateDir (ETFolder.Text) Then          LogFile.Lines.Add('Error Cerate folder ' +ETFolder.Text );    end;    for i:=0 to LBFolders.Count-1 do begin;      SDD.FileName:= LbFolders.Items[i];    cFolder:=  Copy(SDD.FileName, Rpos('\',SDD.FileName)+1, length(SDD.FileName)-Rpos('\',SDD.FileName));      If Not DirectoryExists( ETFolder.Text+'\'+cfolder) then         if Not CreateDir (ETFolder.Text+'\'+cfolder) Then                     LogFile.Lines.Add('Error cerate folder '+ ETFolder.Text+'\'+Info.name);       if FindFirst(SDD.FileName  + '\*.*', faAnyFile and faDirectory, Info)=0 then begin            repeat            if( (Info.Attr and faDirectory=0) ) then begin            if not FileUtil.CopyFile(SDD.FileName+'\'+info.Name , ETFolder.Text+'\'+cfolder+'\'+info.Name, true) then                begin                  LogFile.Lines.Add('Failed to copy file : ' + SDD.FileName+'\'+info.Name)                end             end else begin              if (Info.Name <> '.') and (Info.Name <> '..') then begin                 If Not DirectoryExists( ETFolder.Text+'\'+cfolder+'\'+info.Name) then                    If Not CreateDir (ETFolder.Text+'\'+cfolder+'\'+info.Name) Then                   LogFile.Lines.Add('Error cerate folder '+ ETFolder.Text+'\'+cfolder+'\'+Info.name); //                    SDD.FileName:=SDD.FileName+'\'+info.Name ;                     GetSubFolder(Info.Name ,  SDD.FileName+'\'+info.Name , ETFolder.Text+'\'+cfolder+'\'+Info.name  );              end;          end;             until FindNext(Info) <> 0;            FindClose(Info);        end;     end;     for i:=0 to LBFiles.Count-1 do begin       cFile:=  Copy(LbFiles.Items[i] , Rpos('\',LbFiles.Items[i])+1, length(LbFiles.Items[i])-Rpos('\',LbFiles.Items[i]));       if not FileUtil.CopyFile(LbFiles.Items[i] , ETFolder.Text+'\'+cFile, true) then begin            LogFile.Lines.Add('Failed to copy file : ' + LbFiles.Items[i])       end     end;     LogFile.Lines.SaveToFile(GetUserDir+'\Documents'+'\sbackuplog.log');    end else begin      ShowMessage('Backup can''t create don''t has targer folder information');      ETFolder.SetFocus;    end;  finally    Filesbkp.Free;  end; end; ---------------------------------------------------------------------- Thaddy · 2022-05-24 05:55 In this case it looks that it shows the recovery partition at index 3 , winni's table is not correct: Also note your code contains an error, so the return value is negative. See your output.   FSpace,FSpaceD:longint; should be:   FSpace,FSpaceD:Int64; That is because DiskFree returns Int64 ---------------------------------------------------------------------- trev · 2022-05-24 07:25 Quote from: eldonfsr on May 24, 2022, 04:00:20 amcould be partitions of HDD Please read the documentation for diskfree. ---------------------------------------------------------------------- eldonfsr · 2022-05-24 12:47 Ok Thanks great help... ---------------------------------------------------------------------- winni · 2022-05-24 14:32 Quote from: Thaddy on May 24, 2022, 07:55:30 amIn this case it looks that it shows the recovery partition at index 3 , winni's table is not correct: RTFM ---------------------------------------------------------------------- BobDog · 2022-05-24 15:07 The Winapi will get this task done. 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   useswindows,sysutils; function Disks(whichone:ansistring):double;constd=1024*1024*1024;e='              ';vara,b,c:qword;i:int32;s:ansistring;ret:double;beginret:=0.0;wri teln('Drive',e,'Total Gb',e,'Free Gb');for i:=ord('A') to ord('Z') dobegins:=chr(i)+':';if GetDiskFreeSpaceexA(pchar(s),@a,@b,@c)thenbeginIf (Pos (uppercase(whichone),s)<>0) then ret:=c/d; writeln(chr(i)+':',e,b/d:9: 5,e,c/d:9:5); end;end;writeln;exit(ret)end; var free:double;  beginfree:=disks('c');writeln('Free space on required disk = ',free:9:9,' Gb');writeln('Press return to end');readln;end. ---------------------------------------------------------------------- BobDog · 2022-05-25 06:29 eldonfsr How can I run your procedure procedure TFormMain.BtnStartClick(Sender: TObject); What units must I use. I am using geany ide. I have no access to TFormMain.BtnStartClick ---------------------------------------------------------------------- eldonfsr · 2022-05-26 23:31 Thanks Bob, Give mw new idea to manage that, This my interface components interface uses   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, ComCtrls,   ExtCtrls, Buttons, Grids, StdCtrls, DBGrids, StrUtils, process, BufDataset,   DB, memds, Types;  and this is on Uses... implementation    uses FileUtil,lazfileutils,crt; when start with this i thinking windows is going to show a list of disk drives, as you going testing i learning more..... Thanks.. all take your time and send some text...