I cannot find a command to do this, so I am looking for help here.
I wrote the following code which works most of the time, but not
always:
>>>>>>>>>>>>>>>>>
function df = FreeBytes(disk);
%function df = FreeBytes(disk);
% pass a disk identifier (ie, 'c:\') and the number of free bytes
will be
% returned, the return will be empty if the device is not available
(for
% writing)
[s, w] = dos(['dir ' disk ' /C']); % get a formated dir
inx = findstr(w, 'Dir(s)'); % find the summary line
sdf = w(inx+6:end-11); % get the free bytes
sdf(findstr(sdf,',')) = []; % remove the ','s
df = str2num(sdf); % convert to a number
>>>>>>>>>>>>>>>>>
The code depends on the summary lines being printed by the dos 'dir'
command (I use a windows platform). Unfortunately somtimes when I
add a usb disk the last two summary lines do not appear in the 'w'
variable (above), and so the function returns '[]' -- as if the disk
did not exist.
The above dir command seems to always work when run in the OS's
command window, so I am not sure what is going on here. Matlab
error?
Maybe I am on the wrong track and there is a better way to find the
free space on a disk?
Any help?
thanks, -jeff keating
Titus
"jeff keating" <j_...@yahoo.com> wrote in message
news:eef92...@webx.raydaftYaTP...
-jeff
Peter Boettcher wrote:
>
>
> "jeff keating" <j_...@yahoo.com> writes:
>
>> I need a way to find the available disk space, especially on
> drives
>> that have been added while my matlab process is running (my
runs
> can
>> take a week or more).
>>
>> I cannot find a command to do this, so I am looking for help
> here.
>>
>> I wrote the following code which works most of the time, but
not
>> always:
>>
>>>>>>>>>>>>>>>>>>&
gt;
>>
>> function df = FreeBytes(disk);
>> %function df = FreeBytes(disk);
>> % pass a disk identifier (ie, 'c:\') and the number of free
bytes
>> will be
>> % returned, the return will be empty if the device is not
> available
>> (for
>> % writing)
>>
>> [s, w] = dos(['dir ' disk ' /C']); % get a formated dir
>> inx = findstr(w, 'Dir(s)'); % find the summary line
>> sdf = w(inx+6:end-11); % get the free bytes
>> sdf(findstr(sdf,',')) = []; % remove the ','s
>> df = str2num(sdf); % convert to a number
>>
>>>>>>>>>>>>>>>>>>&
gt;
>
> You might write a MEX function that calls the Windows API
> GetDiskFreeSpaceEx(). In fact, here it is. Compile with
>
> mex diskfree.c
>
>
>