תרגיל בc#

יטרנר

New member
תרגיל בc#

ערב טוב, יש לי בעיה בתרגיל ואשמח אם מישהו יוכל לעזור לי לפתור אותה. התבקשתי לחפש קבצים בעלי סיומות שהוגדרו מראש וליצור מכל קובץ שנמצא מבנה fileData. ניסיתי לפתור זאת כך:
Console.WriteLine("please enter a path"); //string folder = @"c:\projectA\files\"; string folder = Console.ReadLine(); string[] extensions = { "*.txt", "*.DLL", "*.tmp", "*.doc", "*.exe" }; fileData[] arr2 =GetFileData(folder, extensions); foreach (fileData files in arr2) { Console.WriteLine(files); } } public static fileData[] GetFileData(string path, string[] extensions) { int count = 0; for (int i = 0; i < extensions.Length; i++) { string[] files = Directory.GetFiles(path,extensions, SearchOption.TopDirectoryOnly); count += files.Length; //Console.WriteLine("{0} {1} files", files.Length, extensions); } //for checking if it works well: //Console.WriteLine("----------"); //Console.WriteLine("{0} files total",count); fileData[] arr = new fileData[count]; for (int i = 0; i < extensions.Length; i++) { string[] files = Directory.GetFiles(path, extensions, SearchOption.TopDirectoryOnly); for (int j = 0; j < arr.Length; j++) { arr[j].path=files; } } return arr; }
 
למעלה