6

Bug fixed in 12.2.0


Tested with versions 9.0.0, 10.0.2 and 10.3.0, all under OS X 10.10.5. and Linux

The drag-and-drop front-end functionality also results in $Failed.

Surprisingly, Importing, JPEGs, TXTs, and XLSX work just fine!

(* Initialization *)
SetDirectory[NotebookDirectory[]];
text = "Uh oh, this could be a bug";
fileNameTemplate = StringTemplate["s`1`mple file.`2`"];
extensions = { "pdf", "txt", "jpeg", "xlsx"};

$CharacterEncoding

"UTF-8"

(* The list of "a"s used in the test *)
Table[FromCharacterCode@a, {a, 1, 1000}];
as = Select[%, RemoveDiacritics@# == "a" &]

{"a", "à", "á", "â", "ã", "ä", "å", "ā", "ă", "ą", "ǎ", "ǟ", "ǡ", "ǻ", "ȁ", "ȃ", "ȧ", "ɐ", "ɑ", "ɒ"}

(* Exporting files, no failures so far *)
Map[# -> Export[fileNameTemplate @@ #, text] &, Outer[List, as, extensions], {2}]

{a,pdf}->sample file.pdf,
{a,txt}->sample file.txt,
{a,jpeg}->sample file.jpeg,
{a,xlsx}->sample file.xlsx
[...]
{ɒ,pdf}->sɒmple file.pdf,
[...]
{ɒ,xlsx}->sɒmple file.xlsx

(* Re-importing files *)
res = Map[# -> Import@# &, GatherBy[FileNames["*file*"], FileBaseName], {2}];
Drop[res, -1];
%[[-4 ;; -3, 1 ;; 4]] // Flatten // Column

sample file.jpeg-> #image here#
sample file.pdf->{#image here#}
sample file.txt->Uh oh, this could be a bug
sample file.xlsx->{{{Uh oh, this could be a bug}}}
sɐmple file.jpeg-> #image here#
sɐmple file.pdf->$Failed
sɐmple file.txt->Uh oh, this could be a bug
sɐmple file.xlsx->{{{Uh oh, this could be a bug}}}

Only PDFs fail. I've tried a bunch of different $CharacterEncodings, but the only solution so far was to rename the file, work with it, then rename it back, as in this (very rudimentary) example

withFunnyName[filePath_, fun_] := 
 Module[{origName = filePath, tempName, res},
  tempName = CreateTemporary[];
  DeleteFile[tempName];
  RenameFile[origName, tempName];
  res = fun@tempName;
  RenameFile[tempName, origName];
  res

]

What could I be doing wrong? Some system configurations?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Aisamu
  • 2,618
  • 14
  • 17

0 Answers0