Answers for "get random file in directory c#"


get random file in directory c#

using System.IO;
using System.Collections;

var files = Directory.GetFiles("C:/path_example/example", "*.png"); //.png can be changed to match any other desired extentions
string randomFilePath= files[Random.Range(0,files.Length)];
//example output: "C:/path_example/example/pig4.png"
Posted by: Guest on August-14-2021

C# Answers by Framework

Browse Popular Code Answers by Language