Mega Code Archive

 
Categories / Delphi / Hardware
 

Disk total size ,disk free size and is disk in drive ( floppies, zip disks...etc)

Title: disk total size ,disk free size and is disk in drive ? ( floppies, zip disks...etc) Question: sometimes we want to check if disk in drive, what ever the drive is floppies, Zip disk , CDs... etc , also want to know the free and total size of it. Answer: ** updated and thanks for your comments ** we well use a button and DriveComboBox1 ** the function "SetCurrentDir" well be true if the disk in drive and I did not face any error dialogs if there is no disk in drive { thanks Si Carter} ** the procedure "GetDiskFreeSpaceEx" well tell the free and total size ~~ try use this code ~~ uses SysUtils . . . implementation function disk_size (drive :char;var free_size,total_size :int64):boolean; var RootPath: array[0..4] of Char; RootPtr: PChar; current_dir:string; begin RootPath[0] := Drive; RootPath[1] := ':'; RootPath[2] := '\'; RootPath[3] := #0; RootPtr := RootPath; current_dir:=GetCurrentDir; if SetCurrentDir(drive+':\') then begin GetDiskFreeSpaceEx(RootPtr, Free_size, Total_size, nil); SetCurrentDir(current_dir); //this to turn back to originaldir {thanks Bryan Nystrom } result:=true; end else begin result:=false; Free_size:=-1; Total_size:=-1; end; end;// disk_size procedure TForm1.Button1Click(Sender: TObject); var free_size,total_size:int64; //thanks Abdulaziz Jasser begin if disk_size(DriveComboBox1.Drive,free_size,total_size) then showmessage('free space ='+inttostr(free_size)+#13+'total size ='+inttostr(total_size)) else showmessage('disk bot here!'); end; this is used with floppies ,zip disks and CD drivers