【发布时间】:2013-12-09 15:44:44
【问题描述】:
一直在用 C# 处理文件目录的东西,我想我可能只是在这里忘记了一些简单的东西。所以可以说我有 4 个文件夹,我需要检查文件夹是否存在,然后显示文件夹中的文件。但是我坚持的部分是检查让我们说文件的创建日期与四个文件夹之一。几乎就像我错过了文件夹中文件的实际路径一样。这是我到目前为止的代码。
string end; string directoryName; string fileName; string[] listOfFiles; Console.Write("Enter the name of the folder: "); directoryName = Console.ReadLine(); while (directoryName != "end") { if (Directory.Exists(directoryName)) { Console.WriteLine("Directory exists, and it contains the following:"); listOfFiles = Directory.GetFiles(directoryName); for (int x = 0; x < listOfFiles.Length; ++x) Console.WriteLine(" {0}", listOfFiles[x]); } Console.Write("Enter a filename: "); fileName = Console.ReadLine(); if(File.Exists(fileName)) // Almost like a path needs to be here. { Console.WriteLine("File was created " + File.GetCreationTime(fileName)); } }
只是想以防被问到程序 exe 和文件夹都位于一起
【问题讨论】:
标签: c#