简体   繁体   English

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

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

How to get date modified of a file in cloud files? 如何获取云文件中文件的日期修改?

I am using the .net SDK from cloud files (not the rack space nu get package). 我正在使用来自云文件(而不是机架空间nu get软件包)的.net SDK。

I can get a list of my files and call GetStorageItemInformation size but I want to know when the file was put onto cloud files. 我可以获取文件列表并调用GetStorageItemInformation大小,但是我想知道何时将文件放入云文件。 If I use the Cloudberry explorer app I see it has the information. 如果我使用Cloudberry Explorer应用程序,则会看到其中的信息。

Is it in the .net SDK and where? 它在.net SDK中吗?在哪里?

When iterating over the files in your container, you can use OpenStack.NET's ContainerObject.LastModified. 遍历容器中的文件时,可以使用OpenStack.NET的ContainerObject.LastModified。 Here is a console application which lists all containers in a region and their files with the last modified timestamp. 这是一个控制台应用程序,该应用程序列出了区域中的所有容器及其文件,以及上次修改的时间戳。

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();

        }
    }
}

Below is some sample output 以下是一些示例输出

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

If your container has more than 10,000 files, you will need to use the paging parameters to loop through all the files. 如果您的容器中有10,000个以上的文件,则需要使用分页参数来遍历所有文件。 In the example below, I am paging through the results 100 at a time. 在下面的示例中,我一次翻阅结果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