c# - 在文件路径中复制文件夹结构的函数

标签 c# filesystems .net system.io.directory

我需要一个简单的函数,它将 FileInfo 和 destination_directory_name 作为输入,从 fileinfo 获取文件路径并将其复制到作为第二个参数传递的 destination_directory_name 中。

例如。文件路径是“d:\recordings\location1\client1\job1\file1.ext 如果目录不存在,该函数应在 destination_directory_name 中创建目录,并在创建目录后复制文件。

最佳答案

System.IO.Directory.CreateDirectory 可用于创建最终目录,如果路径中的所有文件夹不存在,它也会自动创建。

//Will create all three directories (if they do not already exist).
System.IO.Directory.CreateDirectory("C:\\First\\Second\\Third")

关于c# - 在文件路径中复制文件夹结构的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/438321/

相关文章:

c# - 根据重量将百分比分配给项目

python - 如何查找特定文件的路径

iphone - iOS应用程序中已下载文件的磁盘空间

c# - DateTime 精度差异.NET 与 Java

C# 泛型和约束

C# 访问修饰符取决于状态

c# - 如何将两个字符串(日期和时间)合并为一个 DateTime

c# - 使用 .NET 将文件发布到服务器 HttpWebRequest 或 WebClient

ios - iOS 文件系统如何高效处理单个文件夹中的大量文件

.net - 使用 .Net 库将 CSV 文件上传到 Google Cloud Storage