使用 C# 从 azure 文件存储递归获取文件

2024-03-03

我想编写一个程序来从天蓝色文件存储中获取文件,但问题是目录深度未定义并且isFile文件的属性始终返回 false。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Azure; // Namespace for Azure Configuration Manager
using Microsoft.WindowsAzure.Storage; // Namespace for Storage Client Library
using Microsoft.WindowsAzure.Storage.Blob; // Namespace for Blob storage
using Microsoft.WindowsAzure.Storage.File; // Namespace for File storage

namespace AzureStorage
{
    class Program
    {
        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            //CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            // Create a CloudFileClient object for credentialed access to File storage.
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

            // Get a reference to the file share we created previously.
            CloudFileShare share = fileClient.GetShareReference("my-FileShare");

            // Ensure that the share exists.
            if (share.Exists())
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();


                // Get a reference to the directory we created previously.
                CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("FILES");

                // Ensure that the directory exists.
                if (sampleDir.Exists())
                {
                    var directoryLists = sampleDir.ListFilesAndDirectories();
                    //sampleDir.ge
                    foreach (var yearDirTemp in directoryLists)
                    {
                        var yearDir = sampleDir.GetDirectoryReference(
                                        Path.GetFileNameWithoutExtension(yearDirTemp.Uri.LocalPath)
                                        );
                        foreach (var monthDirTemp in yearDir.ListFilesAndDirectories())
                        {
                            var monthDir = yearDir.GetDirectoryReference(
                                            Path.GetFileNameWithoutExtension(monthDirTemp.Uri.LocalPath)
                                            );
                            foreach (var patientDirTemp in monthDir.ListFilesAndDirectories())
                            {
                                var patientDir = monthDir.GetDirectoryReference(
                                                   Path.GetFileNameWithoutExtension(patientDirTemp.Uri.LocalPath)
                                                   );
                                foreach (var patientDataTemp in patientDir.ListFilesAndDirectories())
                                {
                                    var patientData = patientDir.GetDirectoryReference(
                                                   Path.GetFileNameWithoutExtension(patientDataTemp.Uri.LocalPath)
                                                   );

                                   var fileList = patientData.ListFilesAndDirectories();
                                    foreach(var fileTemp in fileList)
                                    {
                                        // Here fileTemp could be file 
                                        // or directory containing more child directories
                                        var file1 = patientData.GetFileReference(Path.GetFileName(fileTemp.Uri.LocalPath));
                                        file1.FetchAttributes();
                                        byte[] arrTarget = new byte[file1.Properties.Length];
                                        file1.DownloadToByteArray(arrTarget, 0);                                        
                                    }

                                }
                            }

                        }                        
                    }
                }
            }
        }
    }
}

    public static void list_file()
    {
        //***** Get list of all files/directories on the file share*****//
        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("xxxxxxxxxxxxxxxxxxxxxx_AzureStorageConnectionString"));
        CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
        CloudFileShare fileShare = fileClient.GetShareReference("dummyfile");

        // List all files/directories under the root directory.
        Console.WriteLine("Getting list of all files/directories under the root directory of the share.");

        IEnumerable<IListFileItem> fileList = fileShare.GetRootDirectoryReference().ListFilesAndDirectories();

        // Print all files/directories listed above.
        foreach (IListFileItem listItem in fileList)
        {
            // listItem type will be CloudFile or CloudFileDirectory.
            Console.WriteLine(listItem.Uri.Segments.Last());
            Console.WriteLine(listItem.GetType());
            if(listItem.GetType()== typeof(Microsoft.WindowsAzure.Storage.File.CloudFileDirectory))
            {

                list_subdir(listItem);
            }
        }
    }
    public static void list_subdir(IListFileItem list)
    {
        Console.WriteLine("subdir");
        CloudFileDirectory fileDirectory=(CloudFileDirectory)list;
        IEnumerable<IListFileItem> fileList = fileDirectory.ListFilesAndDirectories();


        // Print all files/directories in the folder.
        foreach (IListFileItem listItem in fileList)
        {
            // listItem type will be CloudFile or CloudFileDirectory.
            Console.WriteLine(listItem.Uri.Segments.Last());
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 C# 从 azure 文件存储递归获取文件 的相关文章

  • 如何验证文件名称在 Windows 中是否有效?

    是否有一个 Windows API 函数可以将字符串值传递给该函数 该函数将返回一个指示文件名是否有效的值 我需要验证文件名是否有效 并且我正在寻找一种简单的方法来完成此操作 而无需重新发明轮子 我正在直接使用 C 但针对的是 Win32
  • 访问私人成员[关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 通过将类的私有成员转换为 void 指针 然后转换为结构来访问类的私有成员是否合适 我认为我无权修改包含我需要访问的数据成员的类 如果不道德 我
  • 当我使用“control-c”关闭发送对等方的套接字时,为什么接收对等方的套接字不断接收“”

    我是套接字编程的新手 我知道使用 control c 关闭套接字是一个坏习惯 但是为什么在我使用 control c 关闭发送进程后 接收方上的套接字不断接收 在 control c 退出进程后 发送方的套接字不应该关闭吗 谢谢 我知道使用
  • 如何使用GDB修改内存内容?

    我知道我们可以使用几个命令来访问和读取内存 例如 print p x 但是如何更改任何特定位置的内存内容 在 GDB 中调试时 最简单的是设置程序变量 参见GDB 分配 http sourceware org gdb current onl
  • 将数组向左或向右旋转一定数量的位置,复杂度为 o(n)

    我想编写一个程序 根据用户的输入 正 gt 负 include
  • linux perf:如何解释和查找热点

    我尝试了linux perf https perf wiki kernel org index php Main Page今天很实用 但在解释其结果时遇到了困难 我习惯了 valgrind 的 callgrind 这当然是与基于采样的 pe
  • 如何在列表框项目之间画一条线

    我希望能够用水平线分隔列表框中的每个项目 这只是我用于绘制项目的一些代码 private void symptomsList DrawItem object sender System Windows Forms DrawItemEvent
  • 实时服务器上的 woff 字体 MIME 类型错误

    我有一个 asp net MVC 4 网站 我在其中使用 woff 字体 在 VS IIS 上运行时一切正常 然而 当我将 pate 上传到 1and1 托管 实时服务器 时 我得到以下信息 网络错误 404 未找到 http www co
  • 增加在 Azure 上运行的 Dockerized ASP.NET Core 站点的最大上传大小限制?

    以下是应用程序的架构 使用 ASP NET Core 编写的 Web API Dockerfile 使用以下命令构建 Web 应用程序microsoft dotnet 2 1 sdk并使用执行 APImicrosoft dotnet asp
  • vector 超出范围后不清除内存

    我遇到了以下问题 我不确定我是否错了或者它是一个非常奇怪的错误 我填充了一个巨大的字符串数组 并希望在某个点将其清除 这是一个最小的例子 include
  • Github Action 在运行可执行文件时卡住

    我正在尝试设置运行google tests on a C repository using Github Actions正在运行的Windows Latest 构建过程完成 但是当运行测试时 它被卡住并且不执行从生成的可执行文件Visual
  • 如何使现有 ARM 模板上的资源 API 版本保持最新?

    我有一个现有的 Azure 模板 它配置以下资源 Microsoft ClassicStorage StorageAccounts api version 2014 06 01 microsoft insights components a
  • C++ 复制初始化和直接初始化,奇怪的情况

    在继续阅读本文之前 请阅读在 C 中 复制初始化和直接初始化之间有区别吗 https stackoverflow com questions 1051379 is there a difference in c between copy i
  • C++ fmt 库,仅使用格式说明符格式化单个参数

    使用 C fmt 库 并给定一个裸格式说明符 有没有办法使用它来格式化单个参数 example std string str magic format 2f 1 23 current method template
  • WCF:将随机数添加到 UsernameToken

    我正在尝试连接到用 Java 编写的 Web 服务 但有些东西我无法弄清楚 使用 WCF 和 customBinding 几乎一切似乎都很好 除了 SOAP 消息的一部分 因为它缺少 Nonce 和 Created 部分节点 显然我错过了一
  • 32 位到 64 位内联汇编移植

    我有一段 C 代码 在 GNU Linux 环境下用 g 编译 它加载一个函数指针 它如何执行并不重要 使用一些内联汇编将一些参数推送到堆栈上 然后调用该函数 代码如下 unsigned long stack 1 23 33 43 save
  • x86 上未对齐的指针

    有人可以提供一个示例 将指针从一种类型转换为另一种类型由于未对齐而失败吗 在评论中这个答案 https stackoverflow com questions 544928 reading integer size bytes from a
  • 如何在 C++ BOOST 中像图形一样加载 TIFF 图像

    我想要加载一个 tiff 图像 带有带有浮点值的像素的 GEOTIFF 例如 boost C 中的图形 我是 C 的新手 我的目标是使用从源 A 到目标 B 的双向 Dijkstra 来获得更高的性能 Boost GIL load tiif
  • 限制C#中的并行线程数

    我正在编写一个 C 程序来生成并通过 FTP 上传 50 万个文件 我想并行处理4个文件 因为机器有4个核心 文件生成需要更长的时间 是否可以将以下 Powershell 示例转换为 C 或者是否有更好的框架 例如 C 中的 Actor 框
  • 使用 libcurl 检查 SFTP 站点上是否存在文件

    我使用 C 和 libcurl 进行 SFTP FTPS 传输 在上传文件之前 我需要检查文件是否存在而不实际下载它 如果该文件不存在 我会遇到以下问题 set up curlhandle for the public private ke

随机推荐

  • IEEE 754:为什么谓词 == 和 != 没有发出信号?

    注意 了解IEEE 754 请耐心等待 IEEE 754 2008 表 5 2 列出了五个无序信号谓词及其否定 当关系无序时 它们会导致无效操作异常 该无效操作异常可以防止使用以下代码编写的程序中出现意外的安静 NaN 标准谓词 gt 及其
  • MongoDB Atlas 和适用于 AWS 的 MongoDB Atlas 有什么区别

    在调查物联网数据存储的兼容数据库期间 我研究了 MongoDB 发现定价有点令人困惑 只是想知道有什么区别MongoDB 阿特拉斯 https www mongodb com cloud atlas pricing and 适用于 AWS
  • 提供大型 CSS 文件

    我有一个大约 50k 的大型压缩 CSS 文件 大约有 30 个页面引用了该文件 将 CSS 分离到一个基本文件中 每个页面都有单独的 CSS 文件会显着减少加载时间 还是提供一个大文件实际上是相同的 谢谢 我不完全确定你的意思 但是提供一
  • iOS 中的裁剪区域与选定区域不同?

    这是github上的链接https github com spennyf cropVid tree master https github com spennyf cropVid tree master您自己尝试一下 看看我在说什么 测试需
  • 连续改变 UISlider 拇指图像上 UILabel 的值

    我有一个UISlider 最少 1 个 最多 10 个 我希望它的拇指有一个UILabel放置在它的顶部 在移动时不断更新和更改其文本UISlider的拇指 所以 我从UISlider并添加了一个UILabel但一旦拇指移动 标签似乎会覆盖
  • Cuda C++ 设备代码中没有元组吗?

    global void addKernel int c const int a const int b int i threadIdx x auto lamb int x return x 1 Works auto t std make t
  • Keras 中 Conv1d 中的 input_shape 变量如何工作?

    再见 我正在 Keras 上使用 CNN 1d 但我在输入形状变量方面遇到了很多麻烦 我有一个包含 100 个时间步长和 5 个带有布尔标签的特征的时间序列 我想训练一个使用长度为 10 的滑动窗口的 CNN 1d 这是我编写的非常简单的代
  • 如何将按组绘图元素叠加到 ggplot2 方面?

    我的问题与分面有关 在下面的示例代码中 我查看了一些分面散点图 然后尝试在每个方面覆盖信息 在本例中为平均线 tl dr 版本是我的尝试失败了 要么我添加的平均线计算所有数据 不尊重方面变量 要么我尝试编写一个公式 但 R 抛出错误 然后是
  • 传递带有自定义数据属性的函数

    是否可以传递具有自定义数据属性的函数 这不起作用 div div function hello console log hello 当我获得该属性时 它是一个值为 hello 的字符串而不是函数 怎么解决这个问题呢 你可以这样做 div d
  • 是否可以在 git-extensions 中为特定文件扩展名设置 diff/merge-tool ?

    我刚刚开始使用 LabView 进行开发 这对我来说是全新的 我想使用 git 扩展来处理我的版本控制 由于源位于 vi格式 我无法使用普通的 diff 工具 源是二进制的 幸运的是 LabView 附带了专用的差异和合并工具 这似乎非常有
  • 关于真实的表示可以假设什么?

    该程序返回0在我的机器上 include
  • HTML 数据在 Android 中从 json webservice 获取的 Webview 中无法正确显示?

    我正在使用 json webservice 从服务器获取 HTML 数据并在 webview 中显示 在 iPhone 中可以完美显示屏幕尺寸 但在 Android 中则不能完美显示 这里我放下了webservice链接和代码以及andro
  • Gemfile.lock 应该包含在 .gitignore 中吗?

    我对捆绑器及其生成的文件有点陌生 我有一份来自 GitHub 的 git 存储库副本 该存储库由很多人贡献 因此我惊讶地发现捆绑程序创建了一个存储库中不存在且不在 gitignore list 因为我已经分叉了它 所以我知道将它添加到存储库
  • Javascript 书签在 Firefox 41 中停止工作

    在 Firefox 41 中 小书签 带有javascript 网址 例如javascript alert it works 从点击或关键字运行 停止工作 有没有什么解决办法可以使用javascript Firefox 41 中的书签 以前
  • OpenID Connect 使用 Office 365 和 spring security 登录

    我需要配置OpenID 连接用一个春季安全过滤器以授权使用我的 Rest API Web 我找到了一个谷歌登录示例 http www baeldung com spring security openid connect 但就我而言 我需要
  • 如何删除两个单词之间的字符串

    我正在使用下面的代码行下载网页 WebRequest request WebRequest Create strURL WebResponse response request GetResponse Stream data respons
  • 根据先前的下拉列表选择显示第二个下拉列表

    首先 我讨厌提出一个已经处理过的问题 但你应该知道我在这个网站上找到的其他选项对我不起作用 基本上 我想构建一个简短的表单 其中有两个下拉框 第一个始终显示 第二个默认隐藏 当选择第一个下拉框中的某个选项时 我希望显示第二个下拉框 这是我的
  • 黑莓开发上的脚本语言?

    据我所知 开发 Blackberry 应用程序的首选方法是 Java 这是吗only way 我梦想有一个快速的应用程序环境 您可以在其中创建 GUI 使用 Blackberry UI 组件 类似于 Blackberry 上的 Tcl Tk
  • 循环遍历矩阵的对角线+1

    我需要循环遍历对角线 1 即对角线右侧的值 1 列 并将值写入数据帧中的列 write csv data frame matrix 1 2 matrix 2 3 matrix 3 4 如何使用函数来做到这一点 而不是仅仅列出值的所有位置 实
  • 使用 C# 从 azure 文件存储递归获取文件

    我想编写一个程序来从天蓝色文件存储中获取文件 但问题是目录深度未定义并且isFile文件的属性始终返回 false using System using System Collections Generic using System Lin