How to deal with Chinese Windows path/filename? [duplicate]

I've encountered a problem with Unicode Windows file name.

If I set the file name to Unicode characters on Mac OSX, it works well. But on Windows if the filename starts with a digital number or the filename/path contains Unicode characters, it will not work well. (I am using Chinese Windows version, and Windows may be using GBK codings.)

If the filename starts with a digit, the \ will escape the following digit.

If the filename/path contains a Unicode character, Mathematica will not find the file in some situations.

This works:

This does not work (it tells me the file cannot be found):

Sorry the pictures are captured using Mac (it works), as on Windows system, the path separator will not be / but be \ . So it will cause the problem mentioned above.

Btw, I am using this to get the filename.

Edited

Sorry for late. I managed to find a Windows PC and got the file name as a string.

Here is the Unicode file name on Windows:

ExcelFileName


"C:\Users\jinyongjie\Desktop\20161228合纵科技并购.xlsx"

@Stitch I tried to replace the directory separator, but still cannot work:

StringReplace[ExcelFileName,"\\"->"/"]


"C:/Users/jinyongjie/Desktop/20161228合纵科技并购.xlsx"

marked as duplicate by Alexey Popkov, MarcoB, Itai Seggev, LLlAMnYP, EdmundJul 21 '17 at 20:19

• are you using \\ or \ on windows? – happy fish Mar 17 '17 at 15:49
• Windows generated \ as separator automatically. – cmal Mar 17 '17 at 15:50
• So have you tried escaping the backslash? In other words, you'll use "\\" as the path separator in Mathematica. – Pirx Mar 17 '17 at 15:56
• is your problem :FileNameSetter does not generate double slash for filenames, and that caused file not found problems in some cases? – happy fish Mar 17 '17 at 15:59
• You should be able to use / on Windows as well. – Stitch Mar 17 '17 at 16:29

To Replace \ to / does not work maybe because of the encoding of / is "UTF8", so I use the following expression to split filename to table of strings and then join them back again and intercept them with $PathnameSeparator. StringJoin[Riffle[FileNameSplit[Excel文件名],$PathnameSeparator]]

• Will FileNameJoin @ FileNameSplit[Excel文件名] do the same? – Kuba Mar 20 '17 at 9:36