CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
windows admin

 



Bode
Novice

Feb 14, 2003, 8:17 AM

Post #1 of 13 (2865 views)
windows admin Can't Post

Search user areas on widows 2000 and scan for mp3 files...



Any ideas on how to go about this ?/



Cheers


thodi
stranger

Feb 14, 2003, 11:57 AM

Post #2 of 13 (2854 views)
Re: [Bode] windows admin [In reply to] Can't Post


In Reply To
Search user areas on widows 2000 and scan for mp3 files...
Any ideas on how to go about this ?/

Something like this? http://www.perldoc.com/perl5.8.0/lib/File/Find.html


davorg
Thaumaturge / Moderator

Feb 17, 2003, 2:10 AM

Post #3 of 13 (2847 views)
Re: [Bode] windows admin [In reply to] Can't Post

File::Find is part of the standard Perl distribution.

File::Find::Rule is available on CPAN and is even better.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Bode
Novice

Feb 18, 2003, 7:35 AM

Post #4 of 13 (2840 views)
Re: [davorg] windows admin [In reply to] Can't Post

Cheers for the pointer Wink.

This is the script that I am using is below. its finding the files that I want to find and is telling me the dir that they reside in, which is cool.

The problem is the DIR structure it goes -

\\stu-storage2\

then

DIR 0 (under each of these is the actual users area i.e. all user whos id begins with 0, e.g tr011, xn023)

DIR 1

DIR 2

DIR ..n



Because the script transverses the whole DIR I am having difficulties with getting a handle on each actual user area (dir) so I can build up specific stats i.e the complete size of all the mp3 files on that particular user area. Any ideas ?

use File::Find;
my $ByteCount=0;

find(\&forbiddenSearch, "\\storage-stu2\user-area\");


# Subroutine that determines whether we matched the file extensions.

sub forbiddenSearch {
if ((/\.MP3$/) || (/\.mp3$/) || (/\.mpg$/) || (/^~/) || (/\.wav$/) ){

print "$File::Find::name\n";

my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $therest) = stat($_) or die "Unable to stat $_\n";


print "File Size is $size\n\n";

#$ByteCount += $size;
}
}


davorg
Thaumaturge / Moderator

Feb 18, 2003, 8:05 AM

Post #5 of 13 (2839 views)
Re: [Bode] windows admin [In reply to] Can't Post

Well, apart from the fact I'd use -M instead of stat, that looks find to me. To get subtotal for the particular directories, you could just use a hash to store the sizes of each directory. Extract the relevant part from $File::File::dir each time and increment the relevant value in the hash.

Code
use File::Find; 
my %ByteCount;

find(\&forbiddenSearch, "\\storage-stu2\user-area\");

sub forbiddenSearch {
return unless /\.MP3$/ || /\.mp3$/ || /\.mpg$/ || /^~/
|| /\.wav$/;

print "$File::Find::name\n";

my $size = -M;

print "File Size is $size\n\n";

my $dir = $File::Find::dir; # or extract relevant part

$ByteCount{$dir} += $size;
}


How does that look?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Bode
Novice

Feb 18, 2003, 8:49 AM

Post #6 of 13 (2838 views)
Re: [davorg] windows admin [In reply to] Can't Post

Cheers, thanks alot.



That looks wicked Cool.


Bode
Novice

Feb 19, 2003, 1:11 AM

Post #7 of 13 (2833 views)
Re: [Bode] windows admin [In reply to] Can't Post

In the user areas theres a file called win2k profile, which as far as I know nothing can access. How can I tell the perl progam to ingnore this DIR ?



Cheers


davorg
Thaumaturge / Moderator

Feb 19, 2003, 1:38 AM

Post #8 of 13 (2829 views)
Re: [Bode] windows admin [In reply to] Can't Post

It already does. It only processes MP3, MPEG and WAV files.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Paul
Enthusiast

Feb 19, 2003, 2:38 AM

Post #9 of 13 (2828 views)
Re: [davorg] windows admin [In reply to] Can't Post

>>
/\.MP3$/ || /\.mp3$/
<<

Why not just:

/\.mp3$/i


davorg
Thaumaturge / Moderator

Feb 19, 2003, 2:42 AM

Post #10 of 13 (2826 views)
Re: [Paul] windows admin [In reply to] Can't Post

Not refactoring the original code enough!

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Paul
Enthusiast

Feb 19, 2003, 3:05 AM

Post #11 of 13 (2825 views)
Re: [davorg] windows admin [In reply to] Can't Post

There's no such word as refactoring in my 2000 page Oxford English Dictionary :(


Bode
Novice

Feb 19, 2003, 4:37 AM

Post #12 of 13 (2819 views)
Re: [Paul] windows admin [In reply to] Can't Post

is it possible gather all the DIR names that reside under 1 DIR ?


davorg
Thaumaturge / Moderator

Feb 19, 2003, 5:12 AM

Post #13 of 13 (2817 views)
Re: [Bode] windows admin [In reply to] Can't Post


In Reply To
is it possible gather all the DIR names that reside under 1 DIR ?


Code
@dirs = grep { -d } </path/to/DIR/*>;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives