6
$\begingroup$

Bug introduced in 5.2 or earlier, persisting through 11.2.0 and fixed in 12.3 or earlier [CASE:3962020]
The bug appears on Windows only


I want to rename a .txt file.

For example create a file on your Desktop and name it use TEST.TXT, now I want to rename it to test.txt:

RenameFile["C:\\Users\\Administrator\\Desktop\\TEST.TXT",
           "C:\\Users\\Administrator\\Desktop\\test.txt"]

It seems that RenameFile does not distinguish the UPPER CASE from the lower case in the file extensions. So how can I rename this file?

Ps: I use MATLAB in my homework, but MATLAB can only read *.m in terms of *.M files. So I must rename the *.M files. Therefore I use *.TXT and *.txt to make a example.

$\endgroup$
9
  • $\begingroup$ Works like a charm for me on Linux. $\endgroup$
    – Öskå
    Commented Sep 30, 2014 at 13:58
  • $\begingroup$ I suspect this is an OS problem, since Windows, by default, does not utilize a case-sensitive filesystem, although there are some exceptions. $\endgroup$ Commented Sep 30, 2014 at 14:09
  • 4
    $\begingroup$ I am very happy to learn Mathematica as well as English at the same time here.*^_^* $\endgroup$
    – partida
    Commented Sep 30, 2014 at 14:23
  • 1
    $\begingroup$ Glad to know there is a workaround, but this ought to be reported to wolfram support. $\endgroup$
    – george2079
    Commented Sep 30, 2014 at 19:37
  • 1
    $\begingroup$ @bobthechemist I don't think this is the problem of windows. windows cmd has ren function which has no problem rename upper case to lower case. I think this is apparently a bug. Latest 11.2 still has this problem. $\endgroup$
    – matheorem
    Commented Oct 22, 2017 at 2:39

3 Answers 3

6
$\begingroup$

A simpler alternative:

winRenameFile[f1_, f2_] := Module[{}, RenameFile[f1, "pre" <> f1];
  RenameFile["pre" <> f1, f2]]
$\endgroup$
3
  • $\begingroup$ Crap, that is much simpler. $\endgroup$
    – kale
    Commented Sep 30, 2014 at 14:15
  • $\begingroup$ Ok! Words like a charm in my computer! Thank you everyone! $\endgroup$
    – partida
    Commented Sep 30, 2014 at 14:31
  • $\begingroup$ @user15961 Works* :) $\endgroup$
    – Öskå
    Commented Sep 30, 2014 at 17:52
0
$\begingroup$

i meet the same problem with RenameFile. Somehow when i loop through a folder, it can only rename one file and then pump up with the above error message. It turns out to be, that , the filename you got by FileNames uses single backslash that should be double backslash . So all you need to do is to replace backslash to double backslash. Then it works! Another wired thing is: if you manually copy one filename from the output of FileNames, all the single backslash in that name automatically turns into double backslash. So it seems like when you put such name indirectly into a function, the program fails to make that conversion.

$\endgroup$
0
$\begingroup$

I do not reproduce the bug with Mathematica versions 12.3.1 and 13.1.0 on Windows 10 x64:

screenshot

As one can see from the screenshot, the file is renamed to "pLoT.png", as expected.

Mathematica 8.0.4 on the same machine produces an error message:

screenshot

Hence the bug was fixed in 12.3 or earlier.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.