繁体   English   中英

如何获取云文件中文件的日期修改?

[英]How to get date modified of a file in cloud files?

如何获取云文件中文件的日期修改?

我正在使用来自云文件(而不是机架空间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());
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM