here is a code to list the files I've in a directory, then the user can type the file name to open the file.
public static void openFile()
{
// List files in FormatedDocuments directory
String[] showFiles = Directory.GetFiles("FormatedDocuments");
int filesList = showFiles.GetUpperBound (0) + 1;
const String folderToOpen = @"FormatedDocuments/";
Console.WriteLine ("Here is the list of files:");
for (int i = 0; i < filesList; i++) {
Console.WriteLine ("\tFile : " + Path.GetFileName (showFiles [i]));
}
// When listing is finished, ask the user to select the file he want to open
Console.WriteLine (@"Type the filename (With extension) you want to open:");
String userChoice = folderToOpen + Console.ReadLine ();
Process.Start (userChoice); // Loading with default application regarding the file extension
}
My questions are:
How to list only visible files in the selected directory? [DONE]
How to return in the console a number before each file, and ask the user to type this number instead of the full file name? [Waiting proposition]
I'm a beginner and try to learn by myself, don't be too "expert" in your solution please, I know my current code is not optimized, I try to do it step by step, but I accept your help about this code :)
Thank you for your answers.