Search code examples
perldosexternal-process

How can I get a directory listing from DOS in Perl?


I need to get directory names from the path passed to the Perl script as run time argument. Here is the code I'm using:

$command ="cd $ARGV[0]";
system($command);

$command="dir /ad /b";
system($command);
@files=`$command`;

But it still returns the directory names inside the directory from which I'm running this Perl script. In short, how do I get the directory names from a target directory whose path is passed to this Perl script?


Solution

  • This should also work
    $command = "dir /ad /b $ARGV[0]" ;