Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: File existance check failure

by Festus Hagen (Novice)
on Nov 17, 2012 at 17:22 UTC ( #1004325=note: print w/ replies, xml ) Need Help??


in reply to File existance check failure

Got restless ...

Ok, Took the advice and made a few changes ... :)

I could not get the "when" usage to work!
Running at least Perl v5.16.0
Tried as described in perlsys

So the latest version.

#!/usr/bin/perl use strict; use warnings; # ** # * BCE 42. # * Read a list of file names from a file and delete them. # ** # # ** # * It is what it is, you can do with it as you please. [with respect +, leave the credits] # * # * Just don't blame me if it teaches your computer to smoke! # * # * -Enjoy # * fh :)_~ # ** # # ** Example clean.list # * : Everything after a : and blank lines are ignored # * : Wildcards are valid, be careful. # * : # * # * install_manifest.txt # * cmake_install.cmake # * CMakeCache* # * examples/*.a # ** use File::Basename; my $Prog = "cmake -E"; my $RmDir = "remove_directory"; my $RmFile = "remove -f"; my $RmLink = "remove -f"; sub runCommand { return `$Prog $_[0] \"$_[1]\"` if $_[0] && $_[1]; return -1; } sub cleanup_Link # non Win32 { print "Deleting Link: $_[0]"; runCommand($RmLink, $_[0]); print " ... Deleted!" if not -l $_[0]; print "\n"; } sub cleanup_Dir { print "Deleting Dir : $_[0]"; runCommand($RmDir, $_[0]); print " ... Deleted!" if not -d $_[0]; print "\n"; } sub cleanup_File { print "Deleting File: $_[0]"; runCommand($RmFile, $_[0]); print " ... Deleted!" if not -f $_[0]; print "\n"; } sub cleanup { for (glob qq("$_[0]")) { cleanup_Link($_) if -l; # non Win32 cleanup_Dir ($_) if -d _; cleanup_File($_) if -f _; } } sub main { my $Dir = dirname(__FILE__); open(FILE, "$Dir/clean.list") or die("Unable to open file: $Dir/cl +ean.list."); my @Data = <FILE>; close(FILE); foreach my $line (@Data) { next if $line =~ /^$/; # skip blank lines next if $line =~ /:/; # skip comment lines with ':' (colon) +in them chomp $line; # trim the newline cleanup($line); } } main();

Critiques ??
Comments ??
Suggestions ??
Improvements ??

Thanks

-Enjoy
fh : )_~


Comment on Re: File existance check failure
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-09-19 07:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (132 votes), past polls