mallen has asked for the wisdom of the Perl Monks concerning the following question:

I have a script I am trying to write to delete some files from a couple of folders, those folders are the temp and temp internet files. But my problem is that I need to get to those folders through the users profile name. I do not want to create a script for each person so I need to figure out how to open the dir for the one user by his profile name. One of the folders I am trying to chdir to is C:/Documents and Settings/"div"/Local Settings/Temp. The part in quotes is want I need to use a wildcard with, the div is the first of the profile name. Can someone lead me in the right direction on how to get to these dirs. I want one script for about 200 users. Thanks, Mark

Replies are listed 'Best First'.
Re: wildcards
by esskar (Deacon) on Mar 02, 2004 at 16:27 UTC
    opendir could be your friend:
    my $folder = "C:/Documents and Settings"; my $dh = undef; if(opendir($dh, $folder)) { while(defined(my $file = readdir($dh))) { next if $file =~ /^\.\.?$/; # skip /. and /.. next if -f "$folder/$file"; # skip files print "$folder/$file\n"; } closedir($dh); }
Re: wildcards
by Roy Johnson (Monsignor) on Mar 02, 2004 at 17:57 UTC
    Try looking at $ENV{USERPROFILE} for starters. That may have the C:/Documents and Settings/"div" part of the path for you. If not, from a command prompt, type set and look for a promising variable.

    The PerlMonk tr/// Advocate
Re: wildcards
by TomDLux (Vicar) on Mar 02, 2004 at 17:59 UTC

    You have 200 users using the same PC? WOW!

    When do they all get on? Assuming a 40 hour work week, that means each user gets 3 minutes a week, ignoring the time it takes to log in, log off, not to mention system crashes.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

      I have 200 different laptops that I want to delete the same files from the same folders. I just want one script for all of them. Thats why I need to get the wildcard to work so I do not have to write a user specific script.
        aha...this is much better... maybe print getlogin() is now a choice...