Get Directiry size in windows

W

warrenb101

I'm trying to get the total directory size using perl. Here is a
snippet of what i've got now that doesn't work:

$dirsize = `dir C:\MyDirectory\somefolder . | findstr "File(s)"`;

print "$dirsize\n";


If I run the command from the command prompt it returns the correct
line (which i can later parse out to get the byte count.) but when I
run the perl script it returns results from the directory that the
script is run from not from what i specify in the command.

What am i doing wrong here? Or maybe there is a better way to do
it.....
I'd appreciate anyones help.
Thankx,
WarrenB
 
D

Dark

Win32::DirSize (search.cpan.org is your friend). If you don't or can't
install modules try something like :

$dirsize = `dir \"C:\\Program Files\\\" | findstr \"File(s)\"`;

or

$dirsize = `dir \"C:/Program Files/\" | findstr \"File(s)\"`;

The bottom line is that backticks get interpolated just like double
quotes. I have escaped the other double quotes \" above. Hope it helps.


-I
 
D

Dark

Win32::DirSize (search.cpan.org is your friend). If you don't or can't
install modules try something like :

$dirsize = `dir \"C:\\Program Files\\\" | findstr \"File(s)\"`;

or

$dirsize = `dir \"C:/Program Files/\" | findstr \"File(s)\"`;

The bottom line is that backticks get interpolated just like double
quotes. I have escaped the other double quotes \" above. Hope it helps.


-I
 
P

Paul Lalli

Dark said:
$dirsize = `dir \"C:/Program Files/\" | findstr \"File(s)\"`;

I have escaped the other double quotes \" above.

Yes, you have. Why have you?

Paul Lalli
 
W

warrenb101

Thanks Dark!
Your solution works great.
I looked at Win32::DirSize but the module wasn't available through the
windows perl package manager.

I appreciate the help,
warrenb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top