static public int RandomNumber;
static public int randomIndex;
static Random random = new Random(DateTime.Now.Millisecond);;
public string GetRadomFileFromGivenFolderPath()
{
if (FolderPath_RandomFiles.Text != " ")
{
// Get an array of all file paths in the specified folder
string[] files = Directory.GetFiles(FolderPath_RandomFiles.Text);
// If no files are found, return null
if (files.Length == 0)
{
UpdateRichTextBox("No Files found!");
return "null";
}
// Generate a random number between 0 and the number of files minus 1
do
{
// Generate a random number between 0 and the number of files minus 1
randomIndex = random.Next(0, files.Length - 1);
} while (RandomNumber == randomIndex);
RandomNumber = randomIndex;
// Return the file path at the random index
return RandomFilePath = files[randomIndex];
}
else
{
UpdateRichTextBox("Folder path for \"random Files Path\" not found!");
return "null";
}
}
static public int RandomNumber;
static public int randomIndex;
static Random random = new Random(DateTime.Now.Millisecond);;
public string GetRadomFileFromGivenFolderPath()
{
if (FolderPath_RandomFiles.Text != " ")
{
// Get an array of all file paths in the specified folder
string[] files = Directory.GetFiles(FolderPath_RandomFiles.Text);
// If no files are found, return null
if (files.Length == 0)
{
UpdateRichTextBox("No Files found!");
return "null";
}
// Generate a random number between 0 and the number of files minus 1
do
{
// Generate a random number between 0 and the number of files minus 1
randomIndex = random.Next(0, files.Length - 1);
} while (RandomNumber == randomIndex);
RandomNumber = randomIndex;
// Return the file path at the random index
return RandomFilePath = files[randomIndex];
}
else
{
UpdateRichTextBox("Folder path for \"random Files Path\" not found!");
return "null";
}
}