Solved

WIN32 API function to get Disk free space..

Posted on 2003-11-06
5
786 Views
Last Modified: 2012-08-13
Hi,

  Any way of finding free disk space in pel WIN32 API..???

-Prash
0
Comment
Question by:prashanthgn
  • 2
5 Comments
 
LVL 1

Expert Comment

by:jt401
ID: 9694992
you can use Win32::DriveInfo  -

use Win32::DriveInfo;

$TotalNumberOfFreeBytes = (Win32::DriveInfo::DriveSpace('c:'))[6];
0
 

Author Comment

by:prashanthgn
ID: 9699234
Thanx for the help,

I have 2 more questions,

1.
How to get the number of files and dirs (including files and dirs in the sub dirs).
I tried to use

      use File::Find;
               find(\&Getfiles, "c:\\temp");
               sub Getfiles {
                       ### count files and dirs here....
      }

But this takes a lot of time if the dir contains more number of files ....

Is there any of finding it more quickly....

2.
Is there any function to check if any specified extension  file exists in a dir..??


Thanx in advance
0
 
LVL 1

Accepted Solution

by:
jt401 earned 50 total points
ID: 9702932
It's just natural that it will take longer to do a recursive search if there are many files.. I don't know of any way to speed this up.
If you want to specify several top level directories to search, you can pass an array of dir paths to the sub:

@dirs = qw|c:/temp c:/winnt/system32|;
find(\&Getfiles, @dirs);

# this will print only txt and doc files.
# if you only want the filename and not the complete path
#  use $_ in place of $File::Find::name

sub Getfiles {
   return unless -f $File::Find::name;
   /(\.txt|\.doc)$/i && print "$File::Find::name\n";
}
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10049579
Nothing has happened on this question in more than 8 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by jt401.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check file date before getting folder path 1 80
syslog unix file 20 76
Migrate OTRS to newest version. 1 364
Formatting stings with pack and printf in perl 5 77
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question