-3
したがって、私は500個の.txtファイルにの単語 をたくさん含んでおり、それらの500個のファイルにアクセスし、 (単語はスペースで区切られています。 "/"、 "、"。 "など...) どのようにC#でこれを動作させることができますか? ありがとうございます!試した後1つのフォルダ内の500のテキストファイルにアクセスし、特定のデリメータに基づいてそれらをスプレット表示する
したがって、私は500個の.txtファイルにの単語 をたくさん含んでおり、それらの500個のファイルにアクセスし、 (単語はスペースで区切られています。 "/"、 "、"。 "など...) どのようにC#でこれを動作させることができますか? ありがとうございます!試した後1つのフォルダ内の500のテキストファイルにアクセスし、特定のデリメータに基づいてそれらをスプレット表示する
// Retrieve all the TXT files from the target folder...
String[] filePaths = Directory.GetFiles(@"C:\MyPath\","*.txt");
// Initialize a new data container in the form of a Dictionary...
Dictionary<String, String[]> data = new Dictionary<String, String[]>(filePaths.Length);
// Parse all the TXT files into the Dictionary...
foreach (String filePath in filePaths)
{
String fileName = Path.GetFileNameWithoutExtension(filePath);
String fileContent = File.ReadAllText(filePath);
String[] words = fileContent.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
data.Add(fileName, words);
}
パフォーマンスは素晴らしいではないことを感じる場合は、別のユーザーが既に提案されているように、あなたは、マルチスレッドのアプローチに切り替えることができます。
複数のスレッドとConcurrentDictionary(https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx)を使用することを検討します –
[Reading Files](https ://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-from-a-text-file)、[分割](https:// msdn。 microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx)、[Regex](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex (https://msdn.microsoft.com/en-us/library/dd287191(v = vs.110).aspx)および[スレッド](https://(v = vs.110).aspx)、[ConcurrentDictionary] msdn.microsoft.com/pt-br/library/system.threading.thread(v=vs.110).aspx)。あなたの問題を解決できると思います。 –
を1つずつ読みます。これが長すぎる場合は、マルチスレッドまたは非同期の待機に変更してください。 startetを取得する - それはすぐにそのように完了します。いくつかのMBだけを使って500個のファイルを処理すれば、十分に速くなります。 –