#! /usr/bin/perl
$word_to_delete = "cache";
opendir (DIR,".");
@files = grep(/$word_to_delete/, readdir (DIR));
closedir (DIR);
foreach $file (@files)
{
unlink $file;
}
opendir (DIR,"path/to/dir");
if so you can use Cwd to get the cwd:
#! /usr/bin/perl
use Cwd;
my $dir = getcwd;
my $word_to_delete = "cache";
opendir (DIR,$dir);
@files = grep(/$word_to_delete/, readdir (DIR));
closedir (DIR);
foreach $file (@files)
{
unlink "$dir/$file";
}
remember, deleting files is "dangerous" so test in a dummy directory with dummy files first.
Do you mean I should write the script like this:
#! /usr/bin/perl
use Cwd;
my $dir = getcwd;
my $word_to_delete = "cache";
opendir (DIR,$dir);
@files = grep(/$word_to_delete/, readdir (DIR));
closedir (DIR);
foreach $file (@files)
{
unlink "$dir/$file";
}
or should I include this line somewhere:
opendir (DIR,"path/to/dir");