我想在C#中編寫靜態成員函數,或者在.NET Framework中找到一個將重新指定文件系統指定文件路徑的文件路徑。C#文件路徑回收
例子:
string filepath = @"C:\temp.txt";
filepath = FileUtility.RecaseFilepath(filepath);
// filepath = C:\Temp.TXT
// Where the real fully qualified filepath in the NTFS volume is C:\Temp.TXT
我試過下面的下面的代碼和它的許多變種,它仍然無法正常工作。 我知道Windows在一般情況下不區分大小寫,但我需要將這些文件路徑傳遞給ClearCase,因爲它是Unix和Windows應用程序,所以它考慮文件路徑大小寫。
public static string GetProperFilePathCapitalization(string filepath)
{
string result = "";
try
{
result = Path.GetFullPath(filepath);
DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(result));
FileInfo[] fi = dir.GetFiles(Path.GetFileName(result));
if (fi.Length > 0)
{
result = fi[0].FullName;
}
}
catch (Exception)
{
result = filepath;
}
return result;
}
由於ClearCase。我已經在這個問題上說過了。 – 2009-01-28 05:10:05