如何获取云文件中文件的日期修改?
我正在从云文件(而不是机架空间nu get软件包)中使用.net SDK。
我可以获取文件列表并调用GetStorageItemInformation大小,但是我想知道何时将文件放入云文件。如果我使用Cloudberry Explorer应用程序,则会看到其中的信息。
它在.net SDK中吗?在哪里?
遍历容器中的文件时,可以使用OpenStack.NET的ContainerObject.LastModified。这是一个控制台应用程序,其中列出了区域中的所有容器及其文件,以及最后修改的时间戳。
using System;
using net.openstack.Core.Domain;
using net.openstack.Providers.Rackspace;
namespace CloudFilesDateModified
{
class Program
{
static void Main(string[] args)
{
const string region = "DFW";
var identity = new CloudIdentity { Username = "username", APIKey = "apikey" };
var cloudfiles = new CloudFilesProvider(identity);
foreach (Container container in cloudfiles.ListContainers(region:region))
{
Console.WriteLine($"Container: {container.Name}");
foreach (ContainerObject file in cloudfiles.ListObjects(container.Name, region: region))
{
Console.WriteLine($"\t{file.Name} - {file.LastModified}");
}
}
Console.ReadLine();
}
}
}
以下是一些示例输出
Container: test
foobar - 10/12/2015 2:00:26 PM -06:00
foobar/file.png - 11/6/2015 7:34:42 PM -06:00
foobar/index.html - 11/6/2015 7:34:31 PM -06:00
如果您的容器中有10,000个以上的文件,则需要使用分页参数遍历所有文件。在下面的示例中,我一次翻阅结果100。
foreach (Container container in cloudfiles.ListContainers(region: region))
{
Console.WriteLine($"Container: {container.Name}");
int limit = 100;
string lastFileName = null;
IEnumerable<ContainerObject> results;
do
{
results = cloudfiles.ListObjects(container.Name, region: region, limit: limit, marker: lastFileName);
foreach (ContainerObject file in results)
{
Console.WriteLine($"\t{file.Name} - {file.LastModified}");
lastFileName = file.Name;
}
} while (results.Any());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句