1
我有一個名爲的文件名Pro-Okay.txt我試圖創建一個名爲的文件,如果它不存在,則可以使用Pro-okay.txt。我能夠對文件進行區分大小寫搜索,但是當代碼移動到File.WriteAllText(「Pro-okay.txt」,「」)它會覆蓋Pro-Okay.txt其中已經有信息,我不想覆蓋。是否有可用於創建新的Pro-okay.txt文件的區分大小寫的等價物?C#File.WriteAllText不區分大小寫?
這裏是我當前的代碼:
public static bool FileExistsCaseSensitive(string filename)
{
string name = Path.GetDirectoryName(filename);
return name != null && Array.Exists(Directory.GetFiles(name), s => s == Path.GetFullPath(filename));
}
public void GetProWords(string word)
{
WordDataSet.Clear();
Words.Clear();
Frequency.Clear();
string[] WordSet;
string fname = Environment.CurrentDirectory + "\\Brain\\Pro-" + word + ".txt";
if (FileExistsCaseSensitive(fname))
{
}
else
{
File.WriteAllText(fname, "");
}
TextReader txtReader = new StreamReader(fname);
try
{
while (txtReader.Peek() != -1)
{
string line = txtReader.ReadLine();
if (line.Contains('~'))
{
WordSet = line.Split('~');
Words.Add(WordSet[0].ToString());
Frequency.Add(Convert.ToInt32(WordSet[1]));
}
}
for (int i = 0; i < Words.Count; i++)
{
WordDataSet.Add(new WordData { Word = Words[i], Frequency = Frequency[i] });
}
}
finally
{
txtReader.Close();
}
}
我擔心這是一個文件系統問題:http://superuser.com/questions/266110/how-do-you-make-windows-7-fully-case-sensitive-with-respect-to-the-filesystem。 – meilke
@meilke我擔心你的評論是答案 –