Gossamer Forum
Home : General : Perl Programming :

Delete Files?

Quote Reply
Delete Files?
I am trying to delete all files (.dat) in the 'nm' folder.
This is what I have now

$n = '/..../....../....../nm/'; #basepath
@filelist = ("$n*.dat");
unlink @filelist;

thanks
Paul
Quote Reply
Re: [ceo] Delete Files? In reply to
Try something like;

Code:
my $base = '/full/path/to/folder';

my @list;

$list[0] = 'file1.html';
$list[1] = 'file2.html';
$list[2] = 'file3.html';
$list[3] = 'file4.html';

chdir($base);

foreach (@list) {
system("rm -f $_");
}

...or even better...

Code:
my $base = '/full/path/to/folder';
chdir($base);
system("rm -f *.dat");

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [ceo] Delete Files? In reply to
Sly worked like a dream.....thanks
Quote Reply
Re: [Andy] Delete Files? In reply to
what about even more shorter?

$dir = /home/path/to/dir
unlink glob("$dir/*.html");

thanks,



Quote Reply
Re: [samsara] Delete Files? In reply to
Yeah.. would help if the $dir variable was quoted though Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!