Hi all,

I am trying to make an array of folders and want to basically take all files inside the folder. However, I got an error saying "missing a $ loop variable". I have add a $, and worked around with this codes, but still did not work .. Is it possible to get all files inside an array of folder?

my $folder="1";
my $folder2="2";
my @fld = ($folder, $folder2);
for each (@fld)
{
opendir(FOLD, @fld);
my @FD = readdir(FOLD);
// I want to read all values inside each directories and display it. how to achieve this?
}

Thank you for the guidance

I just found another syntax error, which should be

foreach $fld (@fld)
{
opendir(FOLD, @fld);
my @FD = readdir(FOLD);
// I want to read all values inside each directories and display it. how to achieve this?
}

but still I don't know how to fix this display all files inside the folder arrays. it shows different errors which are : "readdir() attempted on invalid dirhandle FOLD"

Thank you for the guidance

opendir(FOLD, @fld); First error I see is that opendir expects an expression naming one directory. Any variable starting with @ contains an array whereas opendir needs a string representing the name of one directory only.

Yes I understand. thank you for your guidance..!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.