Analyzing multiple files in Folder

Hello All 

I want to write a script that performs same analysis on the multiple trajectory files stored in one Folder say Folder1. Say my project structure is:

Project:

-- Folder1

-- Folder2

-- Folder3

First I intended to do this through \\\$Documents collection but that gives me a list of all the files in project including other sub folders even (or especially) if i run the srcipt from Folder1. I tried to write simple perl script:

#!perl

use strict;
use Getopt::Long;
use MaterialsScript qw(:all);

my \\\$i = 1;
my \\\$dirname = "\\Folder1";

opendir (DIR,\\\$dirname) || die "Can't open folder";
while (my \\\$filename = readdir(DIR)){

my \\\$doc = Documents->Import(\\\$dirname.\\\$filename);

print "\\\$filename\\n";
}
closedir(DIR)

The print is just to check if it works. It does not and i got the "Can't open folder at -e line 10." error. For the record i used / and \\ it does not help. Do you know the solution?


Lukasz