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


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates