Moving All Files from One Folder to Another
Use the following Code Snippet to Move (Cut) all files in a folder to another Folder:
Suppose there are two folders Folder1 and Folder2.. We will move all contents of Folder1 to Folder2:
DirectoryInfo dir1= new DirectoryInfo("F:\Folder1"); DirectoryInfo dir2 = new DirectoryInfo("F:\Folder2"); FileInfo[] Folder1Files = dir1.GetFiles(); if(Folder1Files.Length > 0) { foreach(FileInfo aFile in Folder1Files) { if(File.Exists("F:\Folder2" + aFile.Name)) { File.Delete("F:\Folder2" + aFile.Name); } aFile.MoveTo("F:\Folder2" + aFile.Name); } }
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.