1

Recently I'm dealing with a issue with open Thai named file in folder in development. Usually we do this by:

Java: ProcessBuilder with "explorer /n,/select,/folder/อักษรไทย.jpg"
Windows C API: ShellExecuteW with L"explorer" L"open" L"/n,/select,/folder/อักษรไทย.jpg"

They all work for WinXP system, but failed for Windows Vista and Windows 7.

And the weird thing is, when I removed the combining char from the filename, they all work fine: from อักษรไทย to อกษรไทย.

I've also tried other UTF8 languages like Chinese and Japanese which are both have no combining characters in their char sets.

Also, the Java awt function `Desktop.open(File) works fine for opening such folders or files with combining Thai characters, but unfortunately, I've not found function like that can select a file in folder.

Do you have any ideas about the difference?

Luly
  • 11
  • 2
  • View binary of the file name. Then, compare it with the binary of the file name that you passed to `ShellExecuteW`. It should not matches. If it matched, that mean this is a bug in Windows Vista/7. – UltimaWeapon Jun 21 '13 at 12:10
  • Thank you for your response. And yes, I've also tried with another API ShellExcecuteExW, and pass the exact Unicode bytes of file name to that param of Win API, still it does not accept combining characters. – Luly Jun 25 '13 at 05:39
  • Also, when I tried the "open containing folder" in Firefox's downloads component, and "show in folder" in Chrome's downloads component, they can both open combining path correctly in Win7. And Win7 can open shotcut/link file by "open file location" properly. – Luly Jun 26 '13 at 01:52
  • I wonder which APIs do those functions use. – Luly Jun 26 '13 at 01:53
  • Try `ShellExecuteW(hWnd, NULL, L"full path of directory to open", NULL, NULL, SW_SHOWNORMAL)`. – UltimaWeapon Jun 26 '13 at 04:33
  • I've tried this way as very first way. It does not work even no "/n,/select" parameter attached. – Luly Jun 26 '13 at 06:40
  • Another idea I guess would resolve this is: open the parent folder firstly with Java Desktop.open(File), which is quite easy; and then use some windows MFC handler or some windows API to highlight the file supposed to be chosen. I hope there're some functions that could accept file parameter as a pointer to file instead of a String represent the path or name of that file, in this way, I can pass around the combining character rock. – Luly Jun 26 '13 at 06:50
  • Is http://stackoverflow.com/questions/3010305/programmatically-selecting-file-in-explorer what you want to do? – UltimaWeapon Jun 26 '13 at 10:30
  • Yes, it seems that's close to what I want. I wrote a function: `int BrowseToFile(LPCTSTR filename) { ITEMIDLIST *pidl = ILCreateFromPathW(filename); if(pidl) { int result = SHOpenFolderAndSelectItems(pidl,0,0,0); ILFree(pidl); return result; }else return -1; }` and this returns a value 0x800401F0, which is not even in the `HRESULT` return value list. – Luly Jun 27 '13 at 08:14
  • I guess I forgot this: Remarks CoInitialize or CoInitializeEx must be called before using SHOpenFolderAndSelectItems. Not doing so causes SHOpenFolderAndSelectItems to fail. – Luly Jun 27 '13 at 08:27
  • Thank you so much Putta. This function seems work. I'll see how to apply this to my work. Which I want is to select/highligh a file in its parent folder by Windows Explorer. In this case, only Thai combining character(like ◌็ 0E47 231 ◌่ 0E48 232 ◌้ 0E49 233 ◌๊ 0E4A 234 ◌๋ 0E4B 235 ◌์ 0E4C 236 ◌ํ 0E4D 237 ◌๎ 0E4E 238) cannot be excepted by normal WinAPI in Win7 or Vista. Now, I hope file pointer parameter function would solve this. Thanks again! – Luly Jun 27 '13 at 08:47
  • It resolved my case successfully. Thank you a lot. – Luly Jun 28 '13 at 02:51
  • No problem. It's good to see Thai people in stackoverflow. :) – UltimaWeapon Jun 28 '13 at 04:31

0 Answers0