Solved

WIN32 API function to get Disk free space..

Posted on 2003-11-06
5
760 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now