我们如何跟踪azure文件存储文件夹是否已更新? [英] How do we track azure file storage folder is updated or not?
问题描述
我有azure文件存储,其中包含其他文件夹. 我想检查或跟踪该文件夹的最新更新时间?
I have azure file storage with other folders inside it. I want to check or track when that folder is last updated ?
我已经完成了一个简单的控制台应用程序,可以从该位置获取所有文件-
I have done a simple console application to get all files from that location -
// 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
}
我试图这样得到它,但它是null
.
var test = sourceName.Properties.LastModified;
I tried to get it like this but it is null
.
var test = sourceName.Properties.LastModified;
由于为空,我无法使用此查询:(
because of null i can not able to use this query :(
var latest= fileShare.GetRootDirectoryReference().ListFilesAndDirectories()
.OfType<CloudFileShare>()
.OrderByDescending(m => m.Properties.LastModified)
.ToList()
.First();
我刚刚注意到,我刚刚将一个新文件上传到该文件夹中,但是LastModified仍然是旧日期,这意味着LastModified与该文件夹和文件是分开的:现在该怎么办?
i just noticed that , i have uploaded one new file just now into that folder but still LastModified is old date , it means LastModified is separate for that folder and file :O what to do now ?
我想检查是否在24小时内将任何新文件更新到主文件夹的子文件夹中.
I want to check whether any new file is updated into any sub-fodler of main folder or not within 24hr.
我想知道如何检查该源文件夹中的最新更新文件日期时间吗?
I wonder how to I check the last updated file datetime from that source folder ?
为什么LastModified为null?
why LastModified is null ?
推荐答案
要检索属性值,调用Blob或容器上的
FetchAttributesAsync
方法以填充属性,然后读取值.
To retrieve property values, call the
FetchAttributesAsync
method on your blob or container to populate the properties, then read the values.
运行控制台应用程序时,它实际上会创建一个CloudFileShare
对象的新实例,并且其属性将初始化为默认值.您需要对此调用FetchAttributes
方法以填充属性.
When you run your console app, it essentially creates a new instance of CloudFileShare
object and its properties are initialized to the default value. You would need to call FetchAttributes
method on this to fill the properties.
此外,当您列出文件的属性时,也会提取文件的属性,因此您无需创建CloudFileShare
的新实例.您可以参考此线程.
Also, when you list the file's the properties of the file are fetched as well, you will not need to create a new instance of CloudFileShare
. You could refer to this thread.
您可以在获取属性之前使用 sourceName.FetchAttributes(); .我对其进行了测试,并且效果很好.请参考以下代码:
You could use sourceName.FetchAttributes(); before retrieve property. I test it and it works fine. Please refer to the code as below:
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;
这篇关于我们如何跟踪azure文件存储文件夹是否已更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!