您好我想创建一个连接到我的主机的应用程序,并检查目录中是否添加了任何新文件。 所以我需要该主机文件的创建时间,但我无法连接到服务器。 我只是找到一些服务器文件创建时间的代码,但我不知道为什么他们不工作如何。 有什么建议吗?
这是代码:
string path = "http://neginmelk.ir/app_test\t2/mine.txt";
if (!File.Exists(path))
{
File.Create(path);
}
else
{
// Take an action that will affect the write time.
File.SetLastWriteTime(path, new DateTime(1985,4,3));
}
// Get the creation time of a well-known directory.
DateTime dt = File.GetLastWriteTime(path);
Console.WriteLine("The last write time for this file was {0}.", dt);
// Update the last write time.
File.SetLastWriteTime(path, DateTime.Now);
dt = File.GetLastWriteTime(path);
Console.WriteLine("The last write time for this file was {0}.", dt);
答案 0 :(得分:1)
首先我看到你的路径上有http://
,你想获取远程文件的元数据吗?
您需要在服务器端运行此代码,然后通过GET API / Web服务公开该数据
获取文件/目录的创建时间。
System.IO.File.GetCreationTime('path_to_the_file');
path_to_the_file
必须是本地的。