C# 重命名文件方法


1.                 
       //重命名文件
                        // 改名方法
                        FileInfo fi = new FileInfo("舊路徑"); //xx/xx/aa.rar
                        fi.MoveTo("新路徑"); //xx/xx/xx.rar



2. 文件流方式 using (FileStream fsw = new FileStream(path + newName, FileMode.Create, FileAccess.Write)) //打開文件,用於只寫   { BinaryWriter bw = new BinaryWriter(fsw); //編寫器指向這個文件流   // 遍歷文件合並    for (int i = 0; i < chunks; i++) { bw.Write(System.IO.File.ReadAllBytes(path + i.ToString() + "_" + filename)); //打開一個文件讀取流信息,將其寫入新文件   System.IO.File.Delete(path + i.ToString() + "_" + filename); //刪除指定文件信息   bw.Flush(); //清理緩沖區   } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM