zoukankan      html  css  js  c++  java
  • C# 中移动文件到指定位置

    根据文件后缀名称将文件移动到指定的文件夹下面,具体代码如下:

    demo中使用的是 .png 具体的情况根据你的需求可以更改

     1 using System;
     2 using System.IO;
     3  
     4 public class FileMove
     5 {
     6     public FileMove()
     7     {
     8         // TODO:
     9     }
    10  
    11     // copy all file(*.png) in folder src to dest
    12     private static void moveFiles(string srcFolder, string destFolder)
    13     {
    14         DirectoryInfo directoryInfo = new DirectoryInfo(srcFolder);
    15         FileInfo[] files = directoryInfo.GetFiles();
    16          
    17         foreach (FileInfo file in files) // Directory.GetFiles(srcFolder)
    18         {
    19             if (file.Extension == ".png")
    20             {
    21                 file.MoveTo(Path.Combine(destFolder, file.Name));
    22             }
    23             // will move all files without if stmt 
    24             //file.MoveTo(Path.Combine(destFolder, file.Name));
    25         }
    26     }
    27  
    28     // test demo
    29     static void Main(string[] args)
    30     {
    31         string src = "E:\test\src";
    32         string dest = "E:\test\dest";
    33         //moveFiles(dest, src); // dest -> src
    34         moveFiles(src, dest); // src -> dest
    35         Console.WriteLine("image copy finished!");
    36         Console.ReadLine();
    37          
    38     }
    39 }
  • 相关阅读:
    bcrypt加密算法原理和应用
    spring security 防止iframes攻击
    angularjs在eclipse下不要随意ctrl+shift+f缩进代码
    第五章 容器之元组
    第五章 容器之列表
    第四章 函数
    第3章 编程概论
    mysql排序分组
    数据表的基本操作
    数据库基本操作
  • 原文地址:https://www.cnblogs.com/felix-wang/p/6362236.html
Copyright © 2011-2022 走看看