Hi All,

I'm writing a little script to run through a (large) list of files and test which of the text files contains ^M characters. In doing this, I've used the -T test to narrow the search down. The code (fragment) looks something like this:

foreach my $folder (@folders) { my $folderfullpath = $componentrootpath . "/" . $folder; print "Working with folder " . $folderfullpath . "\n" if ($debug); opendir(my $folderhandle, $folderfullpath); foreach my $element (readdir($folderhandle)) { next if ($element =~ /^\./); my $quotedfullelementpath = "\"" . $folderfullpath . "/" . $elemen +t . "\""; print "\n *** Full element path: " . $quotedfullelementpath . "\n +" if ($debug); next unless (-T $fullelementpath); open (FILE, "<" . $quotedfullelementpath) or die "Can't open file +$quotedfullelementpath:$!\n"; while (<FILE>) { binmode(FILE); my $line1 = unpack("H*", $_); if ($line1 =~ /0d/) { # File is contaminated; print $quotedfullelementpath . " - contaminated\n" if ($debug) +; my ($elementrootname, $elementuuid) = &nameanduuid($fullelemen +tpath); push (@contaminateduuids, $elementuuid) unless ($contaminatedu +uids{$elementuuid}); $contaminateduuids{$elementuuid} = 1; last; } } close (FILE); } }

I introduced the quotes because one of the teams whose code I'm reporting on uses spaces in their filenames. Unfortunately, the quotes seem to nullify the -T test. I tried adding in this piece of debug code:

my $quotedfullelementpath = "\"" . $folderfullpath . "/" . $elemen +t . "\""; my $singlefullelementpath = "'" . $folderfullpath . "/" . $element + . "'"; my $fullelementpath = $folderfullpath . "/" . $element; print "-> " .$quotedfullelementpath . " is "; print "NOT " unless (-T $quotedfullelementpath); print "a text file\n"; print "-> " .$singlefullelementpath . " is "; print "NOT " unless (-T $singlefullelementpath); print "a text file\n"; print "-> " .$fullelementpath . " is "; print "NOT " unless (-T $fullelementpath); print "a text file\n";

and got this output (fragment):

-> "<shortened-path>/ra6535_5.ddl" is NOT a text file -> '<shortened-path>/ra6535_5.ddl' is NOT a text file -> <shortened-path>/ra6535_5.ddl is a text file -> "<shortened-path>/ra6535_6.ddl" is NOT a text file -> '<shortened-path>/ra6535_6.ddl' is NOT a text file -> <shortened-path>/ra6535_6.ddl is a text file -> "<shortened-path>/ra6535_7.ddl" is NOT a text file -> '<shortened-path>/ra6535_7.ddl' is NOT a text file -> <shortened-path>/ra6535_7.ddl is a text file -> "<shortened-path>/ra6536_5.ddl" is NOT a text file -> '<shortened-path>/ra6536_5.ddl' is NOT a text file -> <shortened-path>/ra6536_5.ddl is a text file -> "<shortened-path>/ra6536_6.ddl" is NOT a text file -> '<shortened-path>/ra6536_6.ddl' is NOT a text file -> <shortened-path>/ra6536_6.ddl is a text file

Clearly, these are all text files.

What gives? Is there another test I could use?

Thanks for for your help - Adam...


In reply to File test -T (text) and quoted filenames by AdamtheKiwi

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.