Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Thanks y'all

I have chosen to stick with the simple fexist sub:

sub fexist { my $str = shift; # newMeth REMOVE! # for (glob qq("$_[0]")) { # newMeth CHANGE! for (glob qq("$str")) { return 3 if -l; return 2 if -d _; return 1 if -f _; } return 0; }
Next time I'm working with it I'll make the noted changes and test. (and more likely)

The quoting is the result of hacking to get it to work with spacy names.
I believe it still fails on spacy wildcard names, got real sick and had to put it all aside for now and take care of myself.

Current script, reads a file list of file/directory names and deletes them, Everything after a : and blank lines are ignored.

#!/usr/bin/perl # fh :)_~ # do with as you wish ... # Just don't blame me if it teaches your computer to smoke! use strict; use warnings; use File::Basename; my $Prog = "cmake -E"; my $RmDir = "remove_directory"; my $RmFile = "remove -f"; my $Cmd; sub fexist { my $str = shift; # newMeth REMOVE! # for (glob qq("$_[0]")) { # newMeth ADD! for (glob qq("$str")) { return 3 if -l; return 2 if -d _; return 1 if -f _; } return 0; } sub main { my $dir = dirname(__FILE__); open(FILE, "$dir/clean.list") or die("Unable to open file: $dir/clea +n.list."); my @data = <FILE>; close(FILE); foreach my $line (@data) { next if $line =~ /^$/; # skip blank lines next if $line =~ /:/; # skip lines with a ':' (colon) in them chomp $line; next if not my $rval = fexist $line; $Cmd = join " ", $Prog, ($rval eq 2) ? $RmDir : $RmFile; print "Deleting $line"; system("$Cmd \"$line\""); print " ... Deleted!" unless fexist $line; print "\n"; } } main();

Example clean.list

: Everything after a : and blank lines are ignored : install_manifest.txt cmake_install.cmake cmake_uninstall.cmake CMakeCache.txt Makefile CMakeFiles

Thanks

-Enjoy
fh : )_~


In reply to Re: File existance check failure by Festus Hagen
in thread File existance check failure by Festus Hagen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (8)
    As of 2014-10-23 04:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (124 votes), past polls