RSS Forums RSS
Please support our C# advertiser: Programming Forums

Quick directory question

Join Date: Dec 2003
Posts: 55
Reputation: r0ckbaer is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
r0ckbaer r0ckbaer is offline Offline
Junior Poster in Training

Re: Quick directory question

  #4  
Sep 11th, 2005
ok, this is a function which scans a sourcedir recursively and copies the found files to the target dir:
/// <summary>
		/// 
		/// 
		/// </summary>
		/// <param name="sourceDir">source directory</param>
		/// <param name="targetDir">target directory</param>
		/// <param name="targetDir">file type (mp3)</param>
		static void Mp3FileCopy(string sourceDir, string targetDir, string fileType)
		{
			try
			{
				foreach (string d in Directory.GetDirectories(sourceDir))
				{
					foreach (string f in Directory.GetFiles(d, fileType))
					{
						File.Copy(f, 
							targetDir + "\\" + new FileInfo(f).Name, 
							false);
					}

					Mp3FileCopy(d, targetDir, fileType);
				}
			}
			catch (System.Exception excpt)
			{
				Console.WriteLine(excpt.Message);
			}
		}

you call it like this:
Mp3FileCopy("d:\\download", "d:\\mp3test", "*.mp3");

make sure you created the target dir before attempting to use that function! (replace the source and target dir to your needs!)
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC