- C#
古いDLLは"♥"とかのユニコード文字が使われているファイルにアクセスできないことがあります。
幸いなことにWindowsのファイルは8.3形式の別名のファイル名(ショートファイル名)を持っており、その名前でアクセスすればうまくいく可能性があります。
サンプルコードは以下のようになります。.Net にはショートファイル名を取得する機能がないので、Win32APIを使用して取得します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport(KERNEL32, CharSet = CharSet.Auto)] | |
public extern static int GetShortPathName(string longPath, StringBuilder shortPathBuffer, int bufferSize); | |
// ショートパス名を求める | |
public static string GetShortPathName(string longPath) | |
{ | |
int bufferSize = 260; | |
StringBuilder shortPathBuffer = new StringBuilder(bufferSize); | |
Win32Api.GetShortPathName(longPath, shortPathBuffer, bufferSize); | |
string shortPath = shortPathBuffer.ToString(); | |
return shortPath; | |
} |
0 件のコメント:
コメントを投稿