繁体   English   中英

文件名,目录名或卷标语法不正确,File.Copy

[英]The filename, directory name, or volume label syntax is incorrect, File.Copy

我正在尝试将文件从网络共享文件夹复制到同一网络中的另一个文件夹。 抛出了例外

已验证且文件存在

Source: \\servername\folder1\Old\ABC_1382.pdf

Destination: \\servername\folder1\New\

File.Copy(sourceFilePath, destiFilePath, true);

文件大小为400Kb。

SourceDestination都应该是文件名 如果destiFilePath实际上是一个目录 ,那么让我们添加文件名( ABC_1382.pdf

  string sourceFilePath = @"\\servername\folder1\Old\ABC_1382.pdf";

  string destiFilePath = @"\\servername\folder1\New\";

  // Uncomment, if you are not sure that directory exists 
  // and you want to create it with all subdirs
  // Directory.CreateDirectory(destiFilePath);

  File.Copy(sourceFilePath,
            Directory.Exists(destiFilePath) 
              ? Path.Combine(destiFilePath, Path.GetFileName(sourceFilePath))
              : destiFilePath,
            true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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