• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

@Array = Dir "./cgi-bin/files"; ...?

I Would Like An Example Of Script That Reads The Contents Of A Directory On My Server To An Array.
0
refr
Asked:
refr
1 Solution
 
maholtCommented:
#!/bin/perl

$ls = "/bin/ls"; #location of ls program with options, or dir command on DOS
$diretory = "/export/home/me";  #directory to get listing from

$tmp = `$ls $directory`; #note `` to execute command
@FILES = split(/\s+/,$tmp); #split on white space

0
 
ozoCommented:
#or, more portably:
opendir(DIRHANDLE,$directory) or warn "can't opendir $directory because $!";
@FILES = readdir(DIRHANDLE);

#BTW,
@FILES = `$ls $directory`;
#may have been a more direct way to use the unix specific command
0
 
refrAuthor Commented:
Thank You Both For Your Promptness And Answers.
I Liked ozo's Answer a Smig Better Because Of The Simple "@FILES = `$ls $directory`;" But The Early Bird Gets The Worm I Guess.
otto
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now