How to remove a bunch of .log in windows

S

Sarah

Hello,

I want to remove all the log files in c:\program files\log, so I tried

unlink <c:\\program files\\log\\*.log>;

but it didn't work at all. Then I tried to get all the log file names by

@mylogfiles = glob (c:\\program files\\log\\*.log);

but I didn't get the right log file names.

Could any one help me?

Thanks a lot,
Sarah
 
G

Greg Bacon

: I want to remove all the log files in c:\program files\log, so I tried
:
: unlink <c:\\program files\\log\\*.log>;
:
: but it didn't work at all. Then I tried to get all the log file names by
:
: @mylogfiles = glob (c:\\program files\\log\\*.log);
:
: but I didn't get the right log file names.

Spaces in paths will get you. Modify the code below to taste:

#! perl

use warnings;
use strict;

# i.e., glob "C:\\Program Files\\log\\*.log"

my $path = 'C:\Program Files\log';
opendir my $dir, $path or die "$0: opendir $path: $!\n";

my @files = map "$path\\$_",
grep /\.log$/i,
readdir $dir;

print $_, "\n" for @files;

Hope this helps,
Greg
 
G

Gunnar Hjalmarsson

Sarah said:
I want to remove all the log files in c:\program files\log, so I
tried

unlink <c:\\program files\\log\\*.log>;

but it didn't work at all.

Space in directory name...

Try:

chdir 'c:\program files\log';
unlink said:
Then I tried to get all the log file names by

@mylogfiles = glob (c:\\program files\\log\\*.log);

but I didn't get the right log file names.

my $dir = 'c:\program files\log';
chdir $dir;
my @mylogfiles = map "$dir\\$_", glob '*.log';
 
T

Tore Aursand

I want to remove all the log files in c:\program files\log [...]

Don't try anything fancy. Go with 'File::Find::Rule';

#!/usr/bin/perl
#
use strict;
use warnings;
use File::Find::Rule;

my $dir = 'c:/';
my @log = File::Find::Rule->file()->name( '*.log' )->in( $dir );

foreach my $filename ( @log ) {
unlink( $filename );
}

Not tested, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top