I would suggest a much simpler approach, using .NET Framework built-in classes... using System; using System.IO; namespace RandomFileNames { class Program { static void Main(string[] args) { //choose any folder you like, I used MyDocuments string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); CreateRandomFiles(folder, 10); } static void CreateRandomFiles(string folderName, int numberOfFiles) { string[] extensions = { ".txt", ".exe", ".pdf", ".log", ".xls", ".doc" }; int count = extensions.Length; string fileName; Random random = new Random(); for (int i = 0; i < numberOfFiles; i++) { //this uses the static method GetRandomFileName() //of the Path class try { fileName = Path.GetRandomFileName(); //change the extension to one of your choice fileName = Path.ChangeExtension(fileName, extensions[random.Next(count)]); //create the final file name fileName = Path.Combine(folderName, fileName); //create the file itself File.Create(fileName); } catch (Exception ex) { //handle exceptions here } } } } }
A
Ari123
@Ari123