Board index » cppbuilder » disk space - programmatically.

disk space - programmatically.


2006-01-04 10:51:12 PM
cppbuilder17
Hi,
given a string that represents a directory, e.g. c:\tmp\blah\boo
I would like to determine how many bytes are available in same directory. Does anybody know the windows api I should be looknig at. Don't even know where to start when it comes to windows system programming.
thanks much and have a nice day.
G
 
 

Re:disk space - programmatically.

Thanks a million for that. Do you know what I would call in the case of a directory? i.e. how many bytes are available in c:\tmp\blah\boo as opposed to c:\
thanks
G
" Bruce Salzman" < XXXX@XXXXX.COM >wrote:
Quote

>given a string that represents a directory, e.g. c:\tmp\blah\boo
>
>I would like to determine how many bytes are available in same
>directory. Does anybody know the windows api I should be looknig at.
>Don't even know where to start when it comes to windows system
>programming.

Available space pertains to the disk, not any particular directory.
You can use GetDiskFreeSpace() to find out the free space on a drive.

--
Bruce


 

Re:disk space - programmatically.

helps perfectly. thanks bruce.
G
" Bruce Salzman" < XXXX@XXXXX.COM >wrote:
Quote

"jr ewing" < XXXX@XXXXX.COM >wrote in message
news:43bbf335$ XXXX@XXXXX.COM ...
>
>Thanks a million for that. Do you know what I would call in the case
>of a directory? i.e. how many bytes are available in c:\tmp\blah\boo
>as opposed to c:\
>

You are misunderstanding the notion of available space. The file
system can create files anywhere on a drive partition. So any folder
can contain whatever is available. Of course, FAT, FAT32, and NTFS
file systems have various internal limitations, but are usually not
important for most purposes (at least for the latter two).

HTH,
Bruce


 

{smallsort}

Re:disk space - programmatically.

Quote
given a string that represents a directory, e.g. c:\tmp\blah\boo

I would like to determine how many bytes are available in same
directory. Does anybody know the windows api I should be looknig at.
Don't even know where to start when it comes to windows system
programming.
Available space pertains to the disk, not any particular directory.
You can use GetDiskFreeSpace() to find out the free space on a drive.
--
Bruce
 

Re:disk space - programmatically.

"jr ewing" < XXXX@XXXXX.COM >wrote in message
Quote

Thanks a million for that. Do you know what I would call in the case
of a directory? i.e. how many bytes are available in c:\tmp\blah\boo
as opposed to c:\

You are misunderstanding the notion of available space. The file
system can create files anywhere on a drive partition. So any folder
can contain whatever is available. Of course, FAT, FAT32, and NTFS
file systems have various internal limitations, but are usually not
important for most purposes (at least for the latter two).
HTH,
Bruce
 

Re:disk space - programmatically.

Just one other thing...
I have managed to successfully call the function and its return code indicates no error, i.e. non zero. However I am seeing, the number of free bytes for my drive c: as output by the code below as, to be different to that output by "dir" at the command line.
i.e programmatically I see 923,312,128 UL whereas "dir" reports 13,807,661,056 bytes free. This concerns me as I definitely need to know that the value returned is correct....at least when there are zero bytes free.
does anybody know why there is a discrepency?
DWORD dwBytesPerSector = 0; // bytes per sector
DWORD dwSectorsPerCluster=0; // sectors per cluster
DWORD dwTotalClusters = 0; // total clusters
DWORD dwFreeClusters = 0; // free clusters
DWORD dwFreeSpace = 0; // free space available
if (GetDiskFreeSpace( drive.c_str(),
&dwBytesPerSector,&dwSectorsPerCluster, &dwFreeClusters, &dwTotalClusters) == 0)
{
cout << "Error" << blah blah;
return false;
}
else
{
dwFreeSpace = dwBytesPerSector * dwSectorsPerCluster * dwFreeClusters;
thanks and have a nice day.
Graham
"Jordons Cans" < XXXX@XXXXX.COM >wrote:
Quote

helps perfectly. thanks bruce.

G
" Bruce Salzman" < XXXX@XXXXX.COM >wrote:
>
>"jr ewing" < XXXX@XXXXX.COM >wrote in message
>news:43bbf335$ XXXX@XXXXX.COM ...
>>
>>Thanks a million for that. Do you know what I would call in the case
>>of a directory? i.e. how many bytes are available in c:\tmp\blah\boo
>>as opposed to c:\
>>
>
>You are misunderstanding the notion of available space. The file
>system can create files anywhere on a drive partition. So any folder
>can contain whatever is available. Of course, FAT, FAT32, and NTFS
>file systems have various internal limitations, but are usually not
>important for most purposes (at least for the latter two).
>
>HTH,
>Bruce
>
>

 

Re:disk space - programmatically.

Look up the function GetDiskFreeSpaceEx.
GetDiskFreeSpace is a function which was continued from the days of 16 bit
Windows and only supports values up to 2 Gig.
. Ed
Quote
grahamo wrote in message
news:43bcebbf$ XXXX@XXXXX.COM ...

Just one other thing...

I have managed to successfully call the function and its
return code indicates no error, i.e. non zero. However I am
seeing, the number of free bytes for my drive c: as output
by the code below as, to be different to that output by "dir"
at the command line.

i.e programmatically I see 923,312,128 UL whereas "dir"
reports 13,807,661,056 bytes free. This concerns me as
I definitely need to know that the value returned is correct....
at least when there are zero bytes free.

does anybody know why there is a discrepency?


DWORD dwBytesPerSector = 0; // bytes per sector
DWORD dwSectorsPerCluster=0; // sectors per cluster
DWORD dwTotalClusters = 0; // total clusters
DWORD dwFreeClusters = 0; // free clusters
DWORD dwFreeSpace = 0; // free space available


if (GetDiskFreeSpace( drive.c_str(),
&dwBytesPerSector,&dwSectorsPerCluster, &dwFreeClusters, &dwTotalClusters)
== 0)
{
cout << "Error" << blah blah;
return false;
}
else
{
dwFreeSpace = dwBytesPerSector *
dwSectorsPerCluster * dwFreeClusters;
 

Re:disk space - programmatically.

thanks again. You're spot on. The API exactly matches the output of dir. Nice one dude.
G
"Ed Mulroy" < XXXX@XXXXX.COM >wrote:
Quote
Look up the function GetDiskFreeSpaceEx.

GetDiskFreeSpace is a function which was continued from the days of 16 bit
Windows and only supports values up to 2 Gig.

. Ed

>grahamo wrote in message
>news:43bcebbf$ XXXX@XXXXX.COM ...
>
>Just one other thing...
>
>I have managed to successfully call the function and its
>return code indicates no error, i.e. non zero. However I am
>seeing, the number of free bytes for my drive c: as output
>by the code below as, to be different to that output by "dir"
>at the command line.
>
>i.e programmatically I see 923,312,128 UL whereas "dir"
>reports 13,807,661,056 bytes free. This concerns me as
>I definitely need to know that the value returned is correct....
>at least when there are zero bytes free.
>
>does anybody know why there is a discrepency?
>
>
>DWORD dwBytesPerSector = 0; // bytes per sector
>DWORD dwSectorsPerCluster=0; // sectors per cluster
>DWORD dwTotalClusters = 0; // total clusters
>DWORD dwFreeClusters = 0; // free clusters
>DWORD dwFreeSpace = 0; // free space available
>
>
>if (GetDiskFreeSpace( drive.c_str(),
>&dwBytesPerSector,&dwSectorsPerCluster, &dwFreeClusters, &dwTotalClusters)
>== 0)
>{
>cout << "Error" << blah blah;
>return false;
>}
>else
>{
>dwFreeSpace = dwBytesPerSector *
>dwSectorsPerCluster * dwFreeClusters;