C# 我们如何跟踪azure文件存储文件夹是否已更新?
我有azure文件存储,里面有其他文件夹。 我想检查或跟踪该文件夹上次更新的时间 我已经完成了一个简单的控制台应用程序,以从该位置获取所有文件-C# 我们如何跟踪azure文件存储文件夹是否已更新?,c#,azure,azure-storage,file-storage,C#,Azure,Azure Storage,File Storage,我有azure文件存储,里面有其他文件夹。 我想检查或跟踪该文件夹上次更新的时间 我已经完成了一个简单的控制台应用程序,以从该位置获取所有文件- // Get list of all files/directories on the file share CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["sto
// Get list of all files/directories on the file share
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
IEnumerable<IListFileItem> fileList = sourceName.ListFilesAndDirectories();
CloudFileDirectory destinationDir = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["destinationName"]));
foreach (IListFileItem listItem in fileList)
{
// gives me all file records
}
我刚刚注意到,我刚刚将一个新文件上载到该文件夹中,但LastModified仍然是旧日期,这意味着LastModified对于该文件夹和文件是独立的:O现在该怎么办
我想检查是否有任何新文件在24小时内更新到主文件夹的任何子文件夹中
我想知道如何从源文件夹中检查上次更新的文件日期时间
为什么LastModified为空
要执行此操作,请对blob或容器调用FetchAttributesAsync
方法来填充属性,然后读取值
当您运行console应用程序时,它实际上创建了CloudFileShare
对象的新实例,其属性初始化为默认值。您需要对此调用FetchAttributes
方法来填充属性
此外,当您列出文件的属性时,也会获取文件的属性,您将不需要创建CloudFileShare
的新实例。你可以参考这个
您可以使用sourceName.FetchAttributes()在检索属性之前。我测试了一下,效果很好。请参考以下代码:
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
sourceName.FetchAttributes();
var test = sourceName.Properties.LastModified;
非常感谢这只给了我
sourcename
的LastModified
我想知道sourcename是否有最近更新的子文件夹,那么sourcename
的整体LastModified应该是它的子文件夹值。例如-sourcename在8月11日修改了文件LastModified,而suourcename
中的子文件夹在8月16日修改,则主文件夹的总值为16augYes,这将是最新修改的数据。哦,我刚刚注意到,我刚刚将一个新文件上载到该文件夹中,但LastModified仍然是旧日期,这意味着LastModified对于该文件夹和文件是独立的:O现在要做什么?可以使用DateTime dt=file.GetLastWriteTime(path)代码>以获取修改数据。并遍历文件夹中的所有文件。下面是一个类似的示例。您可以将first
更改为first或default
进行尝试。
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["storageConnectionString"]);
CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings["shareName"]);
var sourceName = fileShare.GetRootDirectoryReference().GetDirectoryReference((ConfigurationManager.AppSettings["sourceName"]));
sourceName.FetchAttributes();
var test = sourceName.Properties.LastModified;