Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2005.02.06;
Скачать: [xml.tar.bz2];

Вниз

Как узнать общий объём логического диска?   Найти похожие ветки 

 
Den303 ©   (2005-01-24 00:06) [0]

Собственно, знаю, что нужно юзать DiskSize(), но почему-то с он мне возвращает непонятное _минусовое_ значение, типа "-148856". Причём с любым аргументом. Хмм... Удивлён :o( Не подскажете, в чём трабла может быть?


 
Anatoly Podgoretsky ©   (2005-01-24 00:25) [1]

Ну наверно ошибка в программе, что еще другого может быть.


 
Defunct ©   (2005-01-24 00:43) [2]

int64 а не integer


 
den303 ©   (2005-01-24 00:49) [3]

Отладчиком прохожу. Оптимизатор выключен. Код
var
 i:int64;
begin
 i:=DiskSize(3);    //3 - диск C
end;

даёт мне i=148856

процедура DiskSize из модуля SysUtils шестых дельфей. Есть ещё предположения?


 
den303 ©   (2005-01-24 00:53) [4]

Упс, описочка вышла. i=-148856


 
GanibalLector ©   (2005-01-24 01:04) [5]

а может попробовать GetDiskFreeSpace


 
den303 ©   (2005-01-24 01:10) [6]

2 GanibalLector
Попробую. А не подскажешь, какие параметры ей нужно, а то у меня справка накрылась почему-то? :o/


 
GanibalLector ©   (2005-01-24 01:14) [7]

2 den303 ©   (24.01.05 01:10) [6]
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

const
DriveConst: array[1..26] of DWord =
   ($1,       $2,       $4,      $8,
    $10,      $20,      $40,     $80,
    $100,     $200,     $400,    $800,
    $1000,    $2000,    $4000,   $8000,
    $10000,   $20000,   $40000,  $80000,
    $100000,  $200000,  $400000, $800000,
    $1000000, $2000000);

type
 TForm1 = class(TForm)
   ComboBox1: TComboBox;
   Label1: TLabel;
   Bevel1: TBevel;
   Button1: TButton;
   procedure FormCreate(Sender: TObject);
   procedure ComboBox1Change(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

 
var
 Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var QQ,i:DWord;
begin
QQ:=GetLogicalDrives();
for i:=1 to 26 do
if (QQ and DriveConst[i])>0 then
Combobox1.Items.Add(chr($40+i)+":\");
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var st:string;
VolumeName,FileSystemName : array [0..MAX_PATH-1] of Char;
VolumeSerialNumber,MaximumComponentLength,FileSystemFlags:DWord;
SectorsPerCluster,BytesPerSector,NumberOfFreeClusters,TotalNumberOfClusters:DWord;
begin

SetErrorMode(SEM_FAILCRITICALERRORS);

case GetDriveType(PChar(Combobox1.Text)) of
0:                st:="Type :"+chr(09)+chr(09)+chr(09)+"Unknown"+#10#13;
1:                st:="Type :"+chr(09)+chr(09)+chr(09)+"No_ROOT_DIR"+#10#13; // if RootPathName=nil
DRIVE_REMOVABLE:  st:="Type :"+chr(09)+chr(09)+chr(09)+"Flopy"+#10#13;
DRIVE_FIXED:      st:="Type :"+chr(09)+chr(09)+chr(09)+"Hard"+#10#13;
DRIVE_REMOTE:     st:="Type :"+chr(09)+chr(09)+chr(09)+"Remote"+#10#13;
DRIVE_CDROM :     st:="Type :"+chr(09)+chr(09)+chr(09)+"CD-ROM"+#10#13;
DRIVE_RAMDISK:    st:="Type :"+chr(09)+chr(09)+chr(09)+"RAM-Disk"+#10#13;end;
st:=st+#10#13;

if GetVolumeInformation(Pchar(Combobox1.Text),VolumeName,MAX_PATH,
@VolumeSerialNumber,MaximumComponentLength,FileSystemFlags,FileSystemName,MAX_PATH)=true  then
       begin
st:=st+"Name :"       +chr(09)+chr(09)+chr(09)+VolumeName+#10#13;
st:=st+"Serial :"     +chr(09)+chr(09)+chr(09)+inttohex(VolumeSerialNumber,8)+#10#13;
st:=st+"Length :"     +chr(09)+chr(09)        +inttostr(MaximumComponentLength)+#10#13;
st:=st+"File system :"+chr(09)+chr(09)        +FileSystemName+#10#13;
       end
else st:=st+"Drive not ready"+#10#13; //ShowMessage(SysErrorMessage(GetLastError));
st:=st+#10#13;

if GetDiskFreeSpace(Pchar(Combobox1.Text),SectorsPerCluster,
BytesPerSector,NumberOfFreeClusters,TotalNumberOfClusters)=true then
       begin
st:=st+"SectorsPerCluster :"+chr(09)+inttostr(SectorsPerCluster)+#10#13;
st:=st+"BytesPerSector : "+chr(09)+inttostr(BytesPerSector)+#10#13;
st:=st+#10#13;
st:=st+"FreeClusters : "+chr(09)+chr(09)+inttostr(NumberOfFreeClusters)+#10#13;
st:=st+"BusyClusters :"+chr(09)+chr(09)+inttostr(TotalNumberOfClusters-NumberOfFreeClusters)+#10#13;
st:=st+"TotalClusters :"+chr(09)+chr(09)+inttostr(TotalNumberOfClusters)+#10#13;
st:=st+#10#13;
st:=st+"FreeBytes :"+chr(09)+chr(09)+inttostr(NumberOfFreeClusters*(Int64(BytesPerSector*SectorsPerCluster)))+#10#13;
st:=st+"Busy :"+chr(09)+chr(09)+chr(09)+inttostr(TotalNumberOfClusters*(Int64(BytesPerSector*SectorsPerCluster))-
NumberOfFreeClusters*(Int64(BytesPerSector*SectorsPerCluster)))+#10#13;
st:=st+"TotalBytes :"+chr(09)+chr(09)+inttostr(TotalNumberOfClusters*(Int64(BytesPerSector*SectorsPerCluster)))+#10#13;
       end;

messagedlg(Pchar(st),MtInformation,[MbOk],0);
end;
     
end.


 
den303 ©   (2005-01-24 01:17) [8]

Ок, большое спасибо! Сейчас проверю...


 
GanibalLector ©   (2005-01-24 01:22) [9]

Хотя...только что полез в DiskSize и вышел на это :


function InternalGetDiskSpace(Drive: Byte;
 var TotalSpace, FreeSpaceAvailable: Int64): Bool;
var
 RootPath: array[0..4] of Char;
 RootPtr: PChar;
begin
 RootPtr := nil;
 if Drive > 0 then
 begin
   RootPath[0] := Char(Drive + $40);
   RootPath[1] := ":";
   RootPath[2] := "\";
   RootPath[3] := #0;
   RootPtr := RootPath;
 end;
 Result := GetDiskFreeSpaceEx(RootPtr, FreeSpaceAvailable, TotalSpace, nil);
end;

так,что...даже не знаю


 
GanibalLector ©   (2005-01-24 01:23) [10]

Вот еще,может поможет :

The GetDiskFreeSpaceEx function obtains information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the total amount of free space available to the user associated with the calling thread.
Windows 95 OSR 2:

The GetDiskFreeSpaceEx function is available on Windows 95 systems beginning with OEM Service Release 2 (OSR 2).
Use the GetVersionEx function to determine that a system is running OSR 2 or a later release of the Windows 95 operating system. The GetVersionEx function fills in the members of an OSVERSIONINFO data structure. If the dwPlatformId member of that structure is VER_PLATFORM_WIN32_WINDOWS, and the low word of the dwBuildNumber member is greater than 1000, the system is running OSR 2 or a later release.

Once you have determined that a system is running OSR 2, call the LoadLibrary or LoadLibraryEx function to load the KERNEL32.DLL file, then call the GetProcAddress function to obtain an address for the GetDiskFreeSpaceEx function. Use that address to call the function.


Хотя,у тя вроде ОС 98


 
GuAV ©   (2005-01-24 02:40) [11]

А если включить опцию Use debug DCUs и пройтись по вызову DiskSize ?


 
Den303 ©   (2005-01-24 03:24) [12]

2 GanibalLector
К сожалению, код из [7] не подходит, т.к. больше 2-х Gb отображать не желает :o(
Может, попробовать GetDiskFreeSpaceEx? Пойду, помучаю...

2 GuAV
Попытаюсь сейчас... ждите результатов :o)


 
den303 ©   (2005-01-24 03:39) [13]

2 GanibalLector
Я, наверное, чего-то туплю. GetDiskFreeSpaceEx выдаёт нормальные результаты, всё путём, а работающая на ней DiskSize несёт чепуху, да ещё отрицательного значения. Странно...
Ладно, сделаю тогда через GetDiskFreeSpaceEx, спасибо!

2 GuAV
Пройтись не успеваю, спать пора. Тока вот скажи, плиз, где эту опцию включить, а то у моих D6 интерфейс русифицированный...


 
jack128 ©   (2005-01-24 03:45) [14]

den303 ©   (24.01.05 3:39) [13]
моих D6 интерфейс русифицированный...

В топку ;-)   Project/Options/Compiler


 
den303 ©   (2005-01-24 09:11) [15]

2 jack128
Знаю, что в топку, но привык как-то с начала работы, и по привычке...

2 All
Хоть и не понял, в чём ошибка была, но после перезапуска Дельфей DiskSize всё правильно стал показывать. ИМХО, глюк был :o/

Тема закрыта, всем большое спасибо!



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2005.02.06;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.046 c
14-1105981791
www.Vlad.uk
2005-01-17 20:09
2005.02.06
Скоро на нашей планете всё время будет ночь!


6-1101151614
userX
2004-11-22 22:26
2005.02.06
Как отправить E-Mail не используя NM сокетов


3-1104973733
Ghost_
2005-01-06 04:08
2005.02.06
генератор отчетов


1-1106561113
slim
2005-01-24 13:05
2005.02.06
помогите перевести на делфи


3-1104994216
korvin
2005-01-06 09:50
2005.02.06
Индексы пакостят?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский