极品分享

C# 修改文件或文件夹名称的方法

方法如下:

            string srcFileName = @"D:/a.txt";
            string destFileName = @"D:/b.txt";
            string srcFolderPath = @"D:/1";
            string destFolderPath = @"D:/6";
            
            //方法一 
            //修改文件名称 
            if (System.IO.File.Exists(srcFileName))
            {
                System.IO.File.Move(srcFileName, destFileName);
            }
            //修改文件夹名称
            if (System.IO.Directory.Exists(srcFolderPath))
            {
                System.IO.Directory.Move(srcFolderPath, destFolderPath);
            }
            
            //方法二 
            //修改文件名称 
            if (System.IO.File.Exists(srcFileName))
            {
                System.IO.FileInfo file = new System.IO.FileInfo(srcFileName);
                file.MoveTo(destFileName);
            }
            /修改文件夹名称
            if (System.IO.Directory.Exists(srcFolderPath))
            {
                System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(srcFolderPath);
                folder.MoveTo(destFolderPath);
            }


2017-04-26 0 /
NET学习
/
标签: 

评论回复

回到顶部