Forum > Beginners
Diskfree prevent message for cardreader
alfware17:
Hallo I am using a loop for all my actual drives of the computer to simply find out whether they exist and have free space. (loop till 30 is enough).
Unfortunately this PC has a cardreader reserved but normally there is nothing in. Both Disksize(i) and Diskfree(i) crash on this drives and I get an not so nice message. The program runs on but I wanted to prevent the message. Has anybody an idea? {$I-} and check IOResult doesn't help as far as I can see. It has result 0.
Here is my test-code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetAnzLW: integer;var i, anz, df, ds: integer; iodisk: integer; home: string;begin {$IFDEF LINUX} GetAnzLw:=1; {$ELSE} anz:=0; PROTO_HOME:=-1; for i:=0 to 30 do if (i<>1) and (i<>2) then begin Write('i=#',i,'#'); GetDir(i, home); Write(' home=#',home,'#'); {$I-} ds:=Disksize(i); {$I+} iodisk:=IOResult; Write(' io=#',iodisk,'#'); if iodisk<>0 then df:=-1; Write(' disksize=#', ds,'#'); {$I-} df:=Diskfree(i); {$I+} iodisk:=IOResult; Write(' io=#',iodisk,'#'); if iodisk<>0 then df:=-1; Write(' diskfree=#', df,'#'); if df > 0 then begin if UpCase(home[1]) = UpCase(PROTO_VERZEICHNIS[1]) then if PROTO_HOME < 0 then PROTO_HOME:=i; if i > 0 then INC(anz); end; Writeln; end; GetAnzLW:=anz; {$ENDIF} end;
engkin:
Can you post a screenshot for the message?
Diskfree uses GetDiskFreeSpaceExA or GetDiskFreeSpaceA
I wonder if you get any message if you use GetDiskFreeSpaceExA directly?
Josh:
not sure, but could the error be due to diskfree returning an int64 value, and you vars are defined as integer (longint);
Function DiskFree(drive: byte) : int64;
Function DiskSize(drive: byte) : int64;
maybe also for completeness change your i declaration to byte; so the types match exactly for the functions your using.
should getdir, also be inside {$I-}{$I+}; could this not fail?
alfware17:
Hallo Josh,
here is my changed code
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetAnzLW: integer;var i: byte; anz: integer; df, ds, dex, dexa: int64; iod, iof, ios, ioex, ioexa: integer; home: string;begin {$IFDEF LINUX} GetAnzLw:=1; {$ELSE} anz:=0; PROTO_HOME:=-1; for i:=0 to 30 do if (i<>1) and (i<>2) then begin Write('i=#',i,'#'); {$I-} GetDir(i, home); {$I+} iod:=IOResult; Write(' io=#',iod,'#'); if iod<>0 then home:=''; Write(' home=#',home,'#'); if iod=0 then begin {$I-} ds:=Disksize(i); {$I+} ios:=IOResult; Write(' io=#',ios,'#'); if ios<>0 then df:=-1; Write(' disksize=#', ds,'#'); {$I-} df:=Diskfree(i); {$I+} iof:=IOResult; Write(' io=#',iof,'#'); if iof<>0 then df:=-1; Write(' diskfree=#', df,'#'); if df > 0 then begin if UpCase(home[1]) = UpCase(PROTO_VERZEICHNIS[1]) then if PROTO_HOME < 0 then PROTO_HOME:=i; if i > 0 then INC(anz); end; Writeln; end; end; Writeln('GetAnzLW=',anz); GetAnzLW:=anz; {$ENDIF} end;
The IOResult is never not zero :o Even not if the drive G and H doesn't really exist (see Screenshot my next post).
Shouldnt be there a function saying if a drive is valid...
alfware17:
Hallo Engkin,
here is my error popup message...
it "crashes" at drive I (and then again at J, K, L what is my builtin cardreader). Unfortunately I also mentioned a wrong drive G and H that should not should not exist with getdir
The message (in German) is saying "no disc in drive".
This program is 32bit Free Pascal Windows - I just checked an older 16bit version virtual (Turbo Pascal), it simply ignores the I drive.
By the way. Can you please give an example of your functions?
"Diskfree uses GetDiskFreeSpaceExA or GetDiskFreeSpaceA"
I could not find in the Sysutils. Here is some from Stackoverflow... Okay I could use my "home" String then but Free Pascal Compiler already missing the
GetDiskFreeSpaceA in any typo tries....
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program FreeDiskSpace;{$APPTYPE CONSOLE}uses SysUtils; const Folder = 'C:\'; var FreeAvailable, TotalSpace: Int64;begin (*GetDiskFreeSpaceA*) if SysUtils.GetDiskFreeSpaceA(PChar(Folder), FreeAvailable, TotalSpace, nil) then begin Writeln(TotalSpace div (1024*1024*1024), 'GB total'); Writeln(FreeAvailable div (1024*1024*1024), 'GB free'); end;end.
Navigation
[0] Message Index
[#] Next page