Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: File deletion

by Rahul6990 (Beadle)
on May 06, 2013 at 12:02 UTC ( #1032261=note: print w/replies, xml ) Need Help??


in reply to File deletion

Hi,

It is very easy in Perl.Use the below steps:

use strict; my $file_location = shift; open(FH,">","log.txt") or die "unable to open file log.txt"; my @files = <$file_location/*>; foreach my $file (@files){ system("rm $file"); unless( $? == -1 ){ print FH "\n$file is deleted.."; } else{ print FH "\n$file is not deleted.. $!"; } } close FH;


Thanks marto for pointing out the error , updated the code, now working correctly.

Replies are listed 'Best First'.
Re^2: File deletion
by marto (Cardinal) on May 06, 2013 at 12:16 UTC

    "It is very easy in Perl"

    Your code doesn't even run.

    Can't take log of 0 at orig.pl line 2

    open. You also don't check for failures when opening the log file.

Re^2: File deletion
by marto (Cardinal) on May 06, 2013 at 12:19 UTC

    Also $file doesn't contain what you assume it does, hence all your deletes fail when you prepend the path.

Re^2: File deletion
by thezip (Vicar) on May 06, 2013 at 18:29 UTC

    Rahul6990,

    It is considered polite around these parts when, if you're going make updates to your posted code, that you indicate the before and after versions of the code. This would be more illustrative and will give others the opportunity to benefit from your mistakes so that they might not have to make them later.

    At the very least, you should give a brief description of the changes you've made, so that some semblance of context/continuity remains.

    </broken_record>



    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens, 1949-2011

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1032261]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2022-11-29 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?