954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

copy all wave files to specified folder- device application

this is not a question, but a code snippet. i attach the project as well.
Form1.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace copyAllWaveFiles
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			// recursive directory search beginning with the root folder
			DirSearch("\\");
		}
		void DirSearch(string sDir)
		{
			try
			{
				Directory.CreateDirectory("\\wavs");
				StreamWriter SW = File.CreateText("\\wavs\\listOfWaves.txt");
				foreach (string d in Directory.GetDirectories(sDir))
				{
					foreach (string f in Directory.GetFiles(d, "*.wav"))
					{
						FileInfo fi = new FileInfo(f);
						fi.CopyTo("\\wavs\\" + fi.Name);
						SW.WriteLine(f);
					}
					DirSearch(d);
				}
				SW.Close();
			}
			catch (Exception ex)
			{
			}
		}
	}
}
Attachments copyAllWaveFiles.zip (27.34KB)
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

i forget that the function is recursive so i made a mistake, here is the corrected version :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace copyAllWaveFiles
{
	public partial class Form1 : Form
	{
		StreamWriter SW;
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			Directory.CreateDirectory("\\wavs");
		   SW = File.CreateText("\\wavs\\listOfWaves.txt");
			// recursive directory search beginning with the root folder
			DirSearch("\\");
			SW.Close();
		}
		void DirSearch(string sDir)
		{
			try
			{
				
				foreach (string d in Directory.GetDirectories(sDir))
				{
					foreach (string f in Directory.GetFiles(d, "*.wav"))
					{
						FileInfo fi = new FileInfo(f);
						fi.CopyTo("\\wavs\\" + fi.Name);
						SW.WriteLine(f);
					}
					DirSearch(d);
				}
			}
			catch (Exception ex)
			{
			}
		}
	}
}
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

here is the new project

Attachments copyAllWaveFiles.zip (28.99KB)
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

my intention was to grab the list of .wav files under windows folder of a pocket pc. After getting this information, i am able to get the common sound files between devices.

Form1.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace copyAllWaveFiles
{
	public partial class Form1 : Form
	{
		StreamWriter SW;
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			Directory.CreateDirectory("\\wavs");
		   SW = File.CreateText("\\wavs\\listOfWaves.txt");
			// recursive directory search beginning with the root folder
			DirSearch("\\Windows");
			// search the files of the folder it self.
			FileSearch("\\Windows");
			SW.Close();
		}
		void DirSearch(string sDir)
		{
			try
			{
				
				foreach (string d in Directory.GetDirectories(sDir))
				{
					FileSearch(d);
					DirSearch(d);
				}
			}
			catch (Exception ex)
			{
			}
		}

		private void FileSearch(string d)
		{
			foreach (string f in Directory.GetFiles(d, "*.wav"))
			{
				FileInfo fi = new FileInfo(f);
				fi.CopyTo("\\wavs\\" + fi.Name, true);
				SW.WriteLine(f);
			}
		}
	}
}
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

here is the new project

Attachments copyAllWaveFiles.zip (29.66KB)
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

to see common files you can use
http://www.daniweb.com/forums/thread196740.html
to see the differences you can use
http://www.daniweb.com/forums/thread196581.html

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You