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 }
  • 相关阅读:
    【JavaWeb 实际项目 03】
    【JavaWeb EL表达式&JSTL标签库 09】
    【JavaWeb jsp 08】
    【JavaWeb 实际项目 02】
    【JavaWeb Servlet 07】
    【JavaWeb Servlet 06】
    【JavaWeb xml&tomcat 05】
    【JavaWeb jQuery 04】
    【JavaWeb jQuery 03】
    【JavaWeb JavaScript 02】
  • 原文地址:https://www.cnblogs.com/felix-wang/p/6362236.html
Copyright © 2011-2022 走看看