Skip to content

Clarify DirectoryNotFoundException behavior for Directory.Move and File.Move destination paths#12881

Draft
adamsitnik with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-directory-move-exception
Draft

Clarify DirectoryNotFoundException behavior for Directory.Move and File.Move destination paths#12881
adamsitnik with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-directory-move-exception

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Directory.Move docs implied DirectoryNotFoundException was only tied to sourceDirName, which was misleading when destination path segments do not exist. File.Move had similar ambiguity around what makes destFileName invalid.

  • Exception contract clarification (System.IO.Directory.Move)

    • Updated DirectoryNotFoundException text to cover invalid paths in either sourceDirName or destDirName.
    • Explicitly calls out missing intermediate directories in destDirName as a triggering condition.
  • Exception contract clarification (System.IO.File.Move overloads)

    • Updated both overloads:
      • File.Move(string sourceFileName, string destFileName)
      • File.Move(string sourceFileName, string destFileName, bool overwrite)
    • Clarified that DirectoryNotFoundException includes cases where one or more directories in destFileName do not exist.
  • Behavior illustrated

Directory.CreateDirectory("src");
Directory.Move("src", "dst/dst"); // throws DirectoryNotFoundException if "dst" does not exist

File.Move("a.txt", "missing/subdir/a.txt"); // throws DirectoryNotFoundException if "missing/subdir" does not exist

Copilot AI changed the title [WIP] Fix Directory.Move throwing exception when destination not exist Clarify DirectoryNotFoundException behavior for Directory.Move and File.Move destination paths Jul 14, 2026
Copilot AI requested a review from adamsitnik July 14, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directory.Move throws when destination not exist

2 participants