| Author |
Dir Command to an array
|
|
| andrewmchorney@cox.net 2005-10-28, 6:56 pm |
| Hello
I would like to execute a dir */s command in windows and save the output into an array. I know I can do this in perl by doing executing the following command in a perl script:
@allfiles = `find / -print`;
How can do this in windows:
Thanks,
Andrew
| |
| Timothy Johnson 2005-10-28, 6:56 pm |
|
The dir command has a /b switch that can be used to get just the
filenames which can be useful for this kind of thing.
If you literally just want an array with the result, then=20
my @allfiles =3D `dir * /s`;
should do the trick.
-----Original Message-----
From: andrewmchorney@cox.net [mailto:andrewmchorney@cox.net]=20
Sent: Friday, October 28, 2005 2:18 PM
To: beginners perl
Subject: Dir Command to an array
Hello
I would like to execute a dir */s command in windows and save the output
into an array. I know I can do this in perl by doing executing the
following command in a perl script:
@allfiles =3D `find / -print`;
How can do this in windows:
Thanks,
Andrew
| |
| Chris Devers 2005-10-28, 6:56 pm |
| | |
| Michael 2005-10-30, 9:56 pm |
| I tried to initialize the variable using the back-ticks methods on my
XP system. But I get errors:
use strict;
my @allfiles = `dir`;
print $allfiles[0];
print "\n";
yields:
"C:\perldata>windir.pl
Use of uninitialized value in string at C:\perldata\windir.pl line 3."
Also - are back-ticks considered bush-league because they present some
kind of security risk?
|
|
|
|