【发布时间】:2015-04-23 11:50:03
【问题描述】:
这是列出我在目录中的文件的代码,然后用户可以键入文件名来打开文件。
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
}
我的问题是:
如何仅列出所选目录中的可见文件? [完成]
如何在控制台中在每个文件前返回一个数字,并要求用户输入这个数字而不是完整的文件名? [等待提议]
我是初学者并尝试自学,请不要对您的解决方案过于“专家”,我知道我当前的代码没有优化,我尝试逐步进行,但我接受您的关于这段代码的帮助:)
感谢您的回答。
【问题讨论】:
标签: c#