Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to rename folders users create on our filesystem and am running into strange problem. Most users are using Macintosh, so I assume problem is closely related to this. Some folders/files appear on our Windows machine to have small dots below letter e or a on occasion. "Dos" and Perl seem to see these characters as "?" while Windows sees it as a black square. The problem is that I cannot rename these files/folders with perl or system ("Dos") calls, thought windows will allow a right click/rename. tried various regex using \? and \s and others, but no help. How can I get perl to rename these?

Replies are listed 'Best First'.
Re: Strange character problem
by fruiture (Curate) on Dec 16, 2002 at 17:38 UTC

    Well, the filenames seem to have characters in them, which mean something different/nothing in the charset you use. You should get the correct names into a string using readdir and can then unpack('c*',...) these to see what's going on.

    There should be a filter for such stuff. How do these people create the directories?

    --
    http://fruiture.de
Re: Strange character problem
by John M. Dlugosz (Monsignor) on Dec 16, 2002 at 22:26 UTC
    Turn on the wide-character API calls for the program. Then use opendir/readdir to see exactly what the characters are, and use that in the source for the renaming.

    If that still has problems (I seem to remember some places where using wide API's didn't actually handle the UCS-2 translation), use Win32::API to access the MoveFile Windows call directly. Also, use a system call to "dir" with the proper flags to get the short name aliases of the files in question, and then use =that= as the source name for the renaming. Hmm, I seem to recall cases where a short name wasn't generated if you had funny chars in the name but it was still short enough, so that might not work.