Re: [vox-tech] Perl help requested

2004-02-10 Thread Peter Jay Salzman
On Tue 10 Feb 04,  9:56 AM, Richard Crawford [EMAIL PROTECTED] said:
 I'm trying to write a Perl application that will go through a directory
 and give the amount of space used by each directory, including each
 subdirectory.  So, for example, if myDirectory1 has three files totalling
 150K and two subdirectories (mySubDirectoryA, with 20K of files, and
 mySubDirectoryB with 50K of files), I'd like to see output like this:
 
 DIRECTORY SIZE
 ==
 myDirectory1  220K
 
 I'm stuck at the first line. Any suggestions?
 
is this a programming exercise or do you just want something to give you
the numbers?

pete

-- 
Make everything as simple as possible, but no simpler.  -- Albert Einstein
GPG Instructions: http://www.dirac.org/linux/gpg
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
___
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] Perl help requested

2004-02-10 Thread Richard Crawford

Peter Jay Salzman said:
 On Tue 10 Feb 04,  9:56 AM, Richard Crawford [EMAIL PROTECTED]
 said:
 I'm trying to write a Perl application that will go through a
 directory and give the amount of space used by each directory,
 including each subdirectory.  So, for example, if myDirectory1 has
 three files totalling 150K and two subdirectories (mySubDirectoryA,
 with 20K of files, and mySubDirectoryB with 50K of files), I'd like to
 see output like this:

 DIRECTORY SIZE
 ==
 myDirectory1  220K

 I'm stuck at the first line. Any suggestions?

 is this a programming exercise or do you just want something to give you
 the numbers?

A programming exercise.  It's something we'll be going back to again and
again.  I'm having trouble installing the FileSys modules, which is making
all of this unnecessarily difficult.


Sláinte,
Richard S. Crawford (AIM: Buffalo2K)

http://www.mossroot.com   http://www.stonegoose.com/catseyeview
Howard Dean for America:  http://www.deanforamerica.com
I really didn't realize the librarians were, you know, such a dangerous
group. They are subversive. You think they're just sitting there at the
desk, all quiet and everything. They're like plotting the revolution, man.
I wouldn't mess with them.
--Michael Moore


___
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] Perl help requested

2004-02-10 Thread Jim Angstadt

--- Richard Crawford [EMAIL PROTECTED]
wrote:
 
 Peter Jay Salzman said:
  On Tue 10 Feb 04,  9:56 AM, Richard Crawford
 [EMAIL PROTECTED]
  said:
  I'm trying to write a Perl application that
 will go through a
  directory and give the amount of space used
 by each directory,
  including each subdirectory.  So, for
 example, if myDirectory1 has
  three files totalling 150K and two
 subdirectories (mySubDirectoryA,
  with 20K of files, and mySubDirectoryB with
 50K of files), I'd like to
  see output like this:
 
  DIRECTORY SIZE
  ==
  myDirectory1  220K
 
  I'm stuck at the first line. Any
 suggestions?
 
  is this a programming exercise or do you just
 want something to give you
  the numbers?
 
 A programming exercise.  It's something we'll
 be going back to again and
 again.  I'm having trouble installing the
 FileSys modules, which is making
 all of this unnecessarily difficult.

snip

File::Find comes to mind.  It is a handy way to
walk a tree, doing whatever you want, at each
file in the tree.

There are probably other better, faster ways but
if you plan on making a project of this, then
this approach might provide a little structure to
build on.

Just a thought,
Jim



__
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
___
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] Perl help requested

2004-02-10 Thread Ken Herron
--On Tuesday, February 10, 2004 09:56:36 -0800 Richard Crawford 
[EMAIL PROTECTED] wrote:

I'm trying to write a Perl application that will go through a directory
and give the amount of space used by each directory, including each
subdirectory.  So, for example, if myDirectory1 has three files
totalling 150K and two subdirectories (mySubDirectoryA, with 20K of
files, and mySubDirectoryB with 50K of files), I'd like to see output
like this:
DIRECTORY SIZE
==
myDirectory1  220K
You know, you're basically describing the du program. Assuming du 
doesn't meet your needs as-is, your perl script could launch du with 
appropriate arguments and massage the output as needed.

For an all-perl solution, I'd probably use File::Find to traverse the 
directory structure of interest and track total sizes using a hash table 
of directory paths. For each file you'll need two pieces of information:

1) its size, obtained by stat'ing it.
2) its pathname, which should be available through a File::Find variable. 
You'll parse this into all of the ((sub-)sub-)directories containing the 
file, in order to collate total sizes by directory.

You'll want to consider the following:

1) Are the sizes of the directories themselves part of the totals? Keep 
in mind that if the directory tree were moved to a different filesystem, 
the directories might a different amount of space.

2) What to do with hard links? If a file appears twice within the 
directory tree, does it count once or twice?

3) What to do with symlinks? The symlink itself takes up a small amount 
of space, and it refers to a file which might or might not be within the 
directory tree.

There's no one right way to handle these; it just depends on what you're 
doing with the totals.

--
Grand Funk Railroad paved the way for Jefferson Airplane, which cleared
the way for Jefferson Starship. The stage was now set for the Alan Parsons
Project, which I believe was some sort of hovercraft. - Homer Simpson
Kenneth Herron[EMAIL PROTECTED]   916-366-7338
___
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech


Re: [vox-tech] Perl help requested

2004-02-10 Thread Micah J. Cowan
On Tue, Feb 10, 2004 at 09:56:36AM -0800, Richard Crawford wrote:
 I'm trying to write a Perl application that will go through a directory
 and give the amount of space used by each directory, including each
 subdirectory.  So, for example, if myDirectory1 has three files totalling
 150K and two subdirectories (mySubDirectoryA, with 20K of files, and
 mySubDirectoryB with 50K of files), I'd like to see output like this:

If this isn't just an excercise in programming, or an improvement over
the existing tool, have you looked into df(1)?

-- 
Micah J. Cowan
[EMAIL PROTECTED]
___
vox-tech mailing list
[EMAIL PROTECTED]
http://lists.lugod.org/mailman/listinfo/vox-tech