我想將我的控制檯應用程序的當前文件夾設置爲用戶在C#中指定的路徑,但我不能。我是編程新手,C#是我的第一語言。 這是迄今爲止的代碼,我不知道我在哪裏出錯我已經在網上搜索這個,按照步驟,但它沒有設置文件夾到用戶指定的。我在這裏要做的是將文件夾路徑更改爲用戶想要的內容,並將其設置爲用戶可以從中訪問其文件的當前文件夾。將文件夾設置爲C#中用戶指定的路徑#
DirectoryInfo folderInfo = new DirectoryInfo("C:\\Windows");
FileInfo[] files = folderInfo.GetFiles();
Console.WriteLine("Enter Folder Name");
string userInput = Console.ReadLine();
FileInfo[] fileType = folderInfo.GetFiles(userInput + "*" + ".", SearchOption.TopDirectoryOnly); //searches for the folder the user has specified
Directory.SetCurrentDirectory(userInput);
Console.WriteLine("{0}", userInput);
Console.ReadLine();
我得到的錯誤是
"An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll"
Additional information: Could not find a part of the path 'folder name here'.
請記住我在這個初學者。 預先感謝您
「不起作用」不是問題陳述。指定您想要的行爲以及您實際獲得的行爲,並告訴我們您收到的錯誤消息(如果有)。 –
完成,多數民衆贊成我得到的錯誤消息 –
你可以提供一些你輸入的示例輸入?例如:無論真正進入''文件夾名稱'這裏' –