zoukankan      html  css  js  c++  java
  • 文件操作文件移动

    移动文件可通过file类的move方法来实现

    格式为:movestring soureceFileNamestring destfileName);

    移动的三个要素:

    源文件存在,目标文件不存在

    源文件存在,目标文件存在

    源文件不存在

     string soupath = @"C:UsersAdministratorDesktopsou123.xlsx";
                string detpath=@"C:UsersAdministratorDesktopdet123.xlsx";
                if (File.Exists(soupath))
                {
                    try
                    {
                        if (!File.Exists(detpath))
                        {
                            File.Move(soupath, detpath);
                            Console.WriteLine("文件移动成功!");
                        }
                        else
                        {
                            Console.WriteLine("目标文件夹中有文件
     1覆盖
     2取消");
                            string userread = Console.ReadLine();
                            if (userread == "1")
                            {
                                Console.WriteLine("文件重名,请修改文件名");
                            }
                            if (userread == "2")
                            {
                                Console.WriteLine("用户取消了操作");
                            }
                        }
    
                    }
    
                    catch (Exception ex)
                    {
    
                        Console.WriteLine("文件移动异常" + ex);
                    }
                }
                else
                {
                    Console.WriteLine("源文件不存在移动文件");
                
                }
    
                Console.Read();
  • 相关阅读:
    树的直径
    POJ3264 Balanced Lineup
    [mock]10月11日
    POJ1062 昂贵的聘礼
    POJ3295 Tautology
    [topcoder]TopographicalImage
    POJ1753 Flip Game
    [leetcode]Copy List with Random Pointer
    [leetcode]Candy
    [leetcode]Gas Station
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8663963.html
Copyright © 2011-2022 走看看