How do I reproduce a DirectoryNotFoundException?
<p>I have a problem with using Phantom do delete and copy recursively. I have already solved the actual problem which was quite easy checking the below exception anyone could easily do so but can you tell me how to reproduce the problem from visual studio?  </p>

<blockquote>
  <p>System.IO.DirectoryNotFoundException:
  Could not find a part of the path
  'build/webui\Views/Web.config'.    at
  System.IO.__Error.WinIOError(Int32
  errorCode, String maybeFullPath)    at
  System.IO.File.InternalCopy(String
  sourceFileName, String destFileName,
  Boolean overwrite)    at
  Phantom.Core.WrappedFileInfo.CopyToDirectory(String
  path) in
  d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\WrappedFileInfo.cs:line
  75    at
  build.$$Execute$closure$23$closure$25.Invoke(WrappedFileSystemInfo
  file)    at
  Phantom.Core.Builtins.UtilityFunctions.ForEach[T](IEnumerable<code>1
  source, Action</code>1 action) in
  d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\Builtins\UtilityFunctions.cs:line
  34    at
  build.$Execute$closure$23.Invoke()<br>
  at Phantom.Core.Target.Execute() in
  d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\Target.cs:line
  81    at
  Phantom.Core.ScriptModel.ExecuteTargets(String[]
  targetNames) in
  d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\ScriptModel.cs:line
  73    at
  Phantom.Program.Execute(String[] args)
  in
  d:\OpenSource\Build\Phantom2\Phantom\src\Phantom\Program.cs:line
  57</p>
</blockquote>

<p>The problem is that phantom is started from .bat/.cmd file and the build file is sent as an argument and this fails somehow on my Windows 7 x64 machine but doing the exact same thing from within Visual Studio 2008 works perfectly so even if I copy the Views folder I can do so recursively. The original code (that fails from the command line):</p>

<pre><code>public override void CopyToDirectory(string path) {
    if (!Directory.Exists(path)) {
        Directory.CreateDirectory(path);
    }

    if (Flatten) {
        var combinedPath = Path.Combine(path, Name);
        File.Copy(FullName, combinedPath, true);
    }
    else {
        var combinedPath = Path.Combine(path, PathWithoutBaseDirectory);
        File.Copy(FullName, combinedPath, true);
    }
}
</code></pre>

<p>Changing the above to:</p>

<pre><code>public override void CopyToDirectory(string path) {
    if (!Directory.Exists(path)) {
        Directory.CreateDirectory(path);
    }

    if (Flatten) {
        var combinedPath = Path.Combine(path, Name);
        File.Copy(FullName, combinedPath, true);
    }
    else {
        var combinedPath = Path.Combine(path, PathWithoutBaseDirectory);
        var newPath = Path.GetDirectoryName(combinedPath);
        if (!Directory.Exists(newPath)) {
            Directory.CreateDirectory(newPath);
        }
        File.Copy(FullName, combinedPath, true);
    }
}
</code></pre>

<p>makes that specific problem go away which is fine I mean figuring it out only took a couple of minutes but trying to reproduce the problem or create a failing test has taken quite a few hours now and I'd like to know why it can't be done or learn how :)</p>

<p><strong>Edit:</strong> The reason for this is extremely silly but here goes. The base directory in this case would be  "Views" the PathWithourBaseDirectory would be equal to something like "Home/About.aspx" the darn thing would not work in cmd but it did work in Visual Studio. Next thing I know I can't make it run in Visual Studio either so I applied my fix and all tests turn green. I still don't know why...</p>
