.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Copy Particular File Extension from One Location to another Location

Posted By:Narayanan       Posted Date: January 24, 2012    Points: 25    Category: File Operation    URL: http://www.dotnetspark.com  

Hew , I give a code for Copy a file from source Path to designation path with Particular File Extension.

        public static void chkDir(string fileDir, string sPath, string fext)
            string[] fsDir = Directory.GetFiles(fileDir);
            foreach (string f in fsDir)
                string fName = f.Substring(fileDir.Length + 1);
                string[] fileExt = fName.Split('.');
                if (fileExt[1] == fext)
                    File.Copy(Path.Combine(fileDir, fName), Path.Combine(sPath, fName), true);

 How to call this Function in the Program?

   It is very simple.
 ChkDir(SorucePath,Designationpath ,fileExtention);
 ChkDir("E:\NewFolder","D:\NewFolder" ,"txt");


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend