Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How much space in a directory

Posted on 1999-07-05
2
Medium Priority
?
188 Views
Last Modified: 2010-03-04
Sorry for the lack of points, but this is all I've got.

How do I find out how much space a dir is taking up?
I need to know how in Perl for Unix and NT.
Thanks
0
Comment
Question by:jknickelbein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
jhurst earned 0 total points
ID: 1213885
assuming that you mean the files in the directoy, not the directory itself, ls -l will give you the size of each file, then use perl to read this output and add the appropriate column
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1213886
> ls -l will give you the size of each file

This will work only on Unix, where ls command is available.

If you are on unix, it can be even simpler. The du command will give you what you want. If you use the -s option, it will give you the space occupied by a directory and all its sub-directories. The value you get is the number of blocks which vary depending on the system. If you want the value in number of kilobytes, use the -k option too.

$space_in_KB = `du -sk $directory`;

On NT there might be a module for this kind of info, but I am not sure. In the absence of a module, you will need to open the directory, read all file names and get the size of each file and add them up.


0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

715 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