C:/Documents and Settings/jmaggard/Desktop/New Folder/ Pg. 4_ 2 x 13? & 3 x 14? is not a directory or file.

We are dragging files created on a mac and giving them an extension, and fixing the file names to be compatible with our workflows and CD burning.

We recieved a CD with some files on them that were named as shown above. The "?" does not show up in Windows as a part of the file name. When you view the file in DOS, the "?" are there. In Hex, the code is 3F, I'm assuming that's an inch mark '"' on the Mac.

The problem is that these files fail a if (-f $_) filetest. How can I reference these files if it fails by name??

Here is the code that processes these files (up to failure):

sub PopulateTree { my $path = shift; my $hashref = shift; wlog("Looking in $path..."); $pathcount++; #Added to get rid of empty dirs my $fixedpath = TrimPath($path); unless (-d $fixedpath) { mkdir $fixedpath, 0777; push @badpaths, $path; wlog( "Bad path found. Marked for deletion." ); } my $dir = new IO::Dir; my @dirContents; unless ($dir->open($path)) { warn("Couldn't open directory $path: $!\n"); return undef; }; unless (@dirContents = $dir->read()) { warn("Couldn't read directory $path: $!\n"); return undef; }; # now look at each item and decide what to do with it if (($#dirContents == 1) && ($path ne $inDir)) { push @badpaths, $path; push @badpaths, $fixedpath; wlog( "Empty path found. Marked for deletion." ); } ITEM: foreach my $item (@dirContents) { if (($item eq '.') || ($item eq '..')) { next ITEM; }; if (-d $path.$item) { # it's a directory, create an item entry for it $hashref->{$item} = { Type => 'Dir', Contents => {} }; # get its contents unless (PopulateTree($path.$item.'/', $hashref->{$item}->{Conten +ts})) { warn("PopulateTree failed"); return undef; }; } elsif (-f _) { # create an item entry for it $hashref->{$item} = { Type => 'File',}; } else { wlog("$path$item is not a directory or file."); }; }; return 1; };

Output:

Looking in C:/Documents and Settings/jmaggard/Desktop/New Folder/... C:/Documents and Settings/jmaggard/Desktop/New Folder/ Pg. 1_ 3 Col. x + 18? is not a directory or file. C:/Documents and Settings/jmaggard/Desktop/New Folder/ Pg. 2_ 3 Col. x + 14? is not a directory or file. C:/Documents and Settings/jmaggard/Desktop/New Folder/ Pg. 3_ 2 Col. x + 13? & 18? is not a directory or file. C:/Documents and Settings/jmaggard/Desktop/New Folder/ Pg. 4_ 2 x 13? +& 3 x 14? is not a directory or file.

The filename in hex:

20 50 67 2E 20 34 5F 20 32 20 78 20 31 33 3F 20 26 20 33 20 78 20 31 3 +4 3F

A screenshot of the file in explorer: http://nothing4sale.org/graphics/funk_folder_snap.jpg

Thanks for your help!
Das Ham

Edit by tye, make link of URL


In reply to Illegal characters in windows filenames? by HamNRye

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.