Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding free disk space

5 views
Skip to first unread message

jeff keating

unread,
Jan 20, 2005, 12:12:39 PM1/20/05
to
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:

>>>>>>>>>>>>>>>>>

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 Edelhofer

unread,
Jan 21, 2005, 3:38:36 AM1/21/05
to
Hi Jeff,
interesting question, and I admit, I don't have an easy answer. Since I'm
also used to
Linux, I have cygwin (www.cygwin.com) installed on my machine and use df to
calculate
the free disk space.
But perhaps someone else has a better idea for you...

Titus


"jeff keating" <j_...@yahoo.com> wrote in message
news:eef92...@webx.raydaftYaTP...

jeff keating

unread,
Jan 25, 2005, 12:47:07 PM1/25/05
to
Thank you very much. Both suggestions are excellent.

-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
>
>
>

Igor

unread,
May 23, 2013, 3:18:11 PM5/23/13
to
"jeff keating" <j_...@yahoo.com> wrote in message <eef92...@webx.raydaftYaTP>...
> I need a way to find the available disk space

This looks pretty much like necroposting, but it's still on the top google's results.

So, I anyone is still looking for a tool to return free space on HDD - try this:

http://www.mathworks.com/matlabcentral/fileexchange/41904-disk-usage
0 new messages