【问题标题】:File.Move all files of type [duplicate]File.Move 类型的所有文件 [重复]
【发布时间】:2017-09-26 11:33:09
【问题描述】:

以下代码正在运行,但我需要对其进行修改,以便它移动 所有 .txt 文件,而不仅仅是 test.txt 文件。

File.Move(@"C:\Desktop\test\test.txt", @"C:\Desktop\test\old\test.txt");

我怎样才能修改它来做到这一点?

将它们从 test 文件夹移动到 test\old 子文件夹

【问题讨论】:

  • 从您要移动的目录中获取 directory.files 集合,然后执行.Where(x => x.EndsWith(".txt"));

标签: c#


【解决方案1】:

这样你可以得到所有带有路径的文件,然后你可以将所有文件复制到你的路径

string[] files = System.IO.Directory.GetFiles(path, "*.txt");

【讨论】:

    猜你喜欢
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 2017-06-21
    相关资源
    最近更新 更多