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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |