Here's the code I currently have to do this:

$startDir = $ARGV[0];

## Main Program ##
$dir = ();
opendir (DIR, $startDir);
foreach $dir (readdir(DIR)) {
        if(($dir ne ".") && ($dir ne "..")){
                CreateChecksum($dir);
        }
}
closedir DIR;

sub CreateChecksum {
        my($dir) = @_;
        #change directories to one in which I want to run checksum and save
the resuls there
        chdir $dir;

        ## WHAT DO I DO HERE? I want to execute something like "sum * >
foobar.txt" ##

        #now change back to the starting directory
        chdir $startDir;
}

I tried something like: system("sum * > foobar.txt") but that's not working
because it looks like that call is being made in the directory the script is
running, instead of the directory I changed to with the "chdir $dir" line of
code. Any ideas? Is there a method that will execute code in the location
specified by a previous call to chdir (as is the case here)? Thanks for your
help.

>  -----Original Message-----
> From:         Torres, Jose  
> Sent: Thursday, May 23, 2002 12:03 PM
> To:   '[EMAIL PROTECTED]'
> Subject:      command-line commands within a Perl script
> 
> Hi,
> 
> I have a directory with several subdirectories, each full of several dozen
> Word files. For each subdirectory,  I need to run the checksum app against
> all of that directory's files and output a file into that directory with
> the checksum results. How can I do this? I'm very unfamilar with running
> command-line commands from within an Perl script. I know to change
> directories, you can do something like this:
> 
> $changeDir = "cd ".$startingDir;
> system($changeDir);
> 
> but what about retrieving the list of subdirectories from the starting
> directory? How can I do this? 
> Thanks for your help.
> 
> 
> -Jose
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to