Moving files based on name to the corresponding folder
<p>Hello everyone and well met!  I have tried a lot of different methods/programs to try and solve my problem.  I'm a novice programmer and have taken a Visual Basic Class and Visual C# class.</p>

<p>I'm working with this in C#</p>

<p>I started off by making a very basic move file program and it worked fine for one file but as I mentioned I will be needing to move a ton of files based on name</p>

<p>What I am trying to do is move .pst (for example dave.pst) files from my exchange server based on username onto a backup server in the users folder (folder = dave) that has the same name as the .pst file</p>

<p>The ideal program would be:
Get files from the folder with the .pst extension
Move files to appropriate folder that has the same name in front of the .pst file extension


<p>Update:</p>

<pre><code>// String pstFileFolder = @"C:\test\";
// var searchPattern = "*.pst";
// var extension = ".pst";
//var serverFolder = @"C:\test3\";
// String filename = System.IO.Path.GetFileNameWithoutExtension(pstFileFolder);
// Searches the directory for *.pst

DirectoryInfo sourceDirectory = new DirectoryInfo(@"C:\test\");
String strTargetDirectory = (@"C:\test3\");
Console.WriteLine(sourceDirectory);
Console.ReadKey(true);&gt;foreach (FileInfo file in sourceDirectory.GetFiles()) {
    Console.WriteLine(file);
    Console.ReadKey(true);

    // Try to create the directory.
    System.IO.Directory.CreateDirectory(strTargetDirectory);
    file.MoveTo(strTargetDirectory + "\\" + file.Name);
}
</code></pre>

<p>This is just a simple copy procedure.  I'm completely aware.  The </p>

<blockquote>
  <p>Console.WriteLine(file);
  Console.ReadKey(true);</p>
</blockquote>

<p>Are for verification purpose right now to make sure I'm getting the proper files and I am.  Now I just need to find the folder based on the name of the .pst file(the folder for the users are already created), make a folder(say 0304 for the year), then copy that .pst based on the name.</p>

<p>Thanks a ton for your help guys. @yuck, thanks for the code.</p>
