Get Directiry size in windows

Discussion in 'Perl Misc' started by warrenb101@hotmail.com, Sep 6, 2006.

  1. Guest

    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
     
    , Sep 6, 2006
    #1
    1. Advertising

  2. Dark Guest

    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


    wrote:
    > 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
     
    Dark, Sep 6, 2006
    #2
    1. Advertising

  3. Dark Guest

    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


    wrote:
    > 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
     
    Dark, Sep 6, 2006
    #3
  4. Paul Lalli Guest

    Dark wrote:
    > $dirsize = `dir \"C:/Program Files/\" | findstr \"File(s)\"`;
    >
    > I have escaped the other double quotes \" above.


    Yes, you have. Why have you?

    Paul Lalli
     
    Paul Lalli, Sep 6, 2006
    #4
  5. Guest

    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



    Dark wrote:
    > 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)\"`;
    >
     
    , Sep 6, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Madhanmohan S
    Replies:
    5
    Views:
    7,820
    Madhanmohan S
    Sep 3, 2004
  2. Andreas Klemt
    Replies:
    6
    Views:
    11,319
    Peter Theill
    Nov 28, 2004
  3. =?Utf-8?B?QmlkYXJrb3Rh?=

    How to set the DataGrid Row Size to a fixed size.

    =?Utf-8?B?QmlkYXJrb3Rh?=, May 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    848
    =?Utf-8?B?QmlkYXJrb3Rh?=
    May 19, 2005
  4. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,705
    Michael Jung
    May 25, 2008
  5. Pallav singh
    Replies:
    2
    Views:
    312
    Bo Persson
    Apr 7, 2009
Loading...

Share This Page