简体   繁体   中英

Directory.Move on remote directory causes DirectoryNotFoundException, but directory exists

We have a service that does something similar to the following:

var dir =        @"\\network-fileshare\logs\special\1";
var anotherDir = @"\\network-fileshare\logs\1";

if (Directory.Exists(dir))
{
    Directory.Move(dir, anotherDir);
}

It sometimes throws a DirectoryNotFoundException when moving the directory, saying that it "Could not find part of the path" for the directory we're trying to move (ie dir ).

What baffles me is:

  1. We check the directory exists, yet the exception message says it cannot be found.
  2. That this error occurs intermittently. Majority of the time it works; once in a blue moon it doesn't.
  3. I've verified that the directory to be moved exists in our fileshare.

Are there any other potential causes of a DirectoryNotFoundException ?

Network issues might cause this problem as well. You can consider using Mapped Network Drive letters but based on my experience, it's really hard to solve it unless you redesigned network structure. Anyway, it's just my opinion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM