简体   繁体   English

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

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

I'm trying to copy a file from network shared folder to another folder in the same network. 我正在尝试将文件从网络共享文件夹复制到同一网络中的另一个文件夹。 It threws the exception . 抛出了例外

Verified and the file exists . 已验证且文件存在

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

Destination: \\servername\folder1\New\

File.Copy(sourceFilePath, destiFilePath, true);

The file size is 400Kb. 文件大小为400Kb。

Both Source and Destination should be file names . SourceDestination都应该是文件名 If destiFilePath is in fact a directory , let's add source file name ( ABC_1382.pdf ) 如果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.

相关问题 File.Copy 抛出“文件名、目录名或卷 label 语法不正确”错误 - File.Copy Throwing throw “The filename, directory name, or volume label syntax is incorrect” error File.Copy错误-C#-IOException文件名,目录名或卷标签 - File.Copy error - C# - IOException The filename, directory name, or volume label windres:文件名,目录名或卷标签语法不正确 - windres: The filename, directory name, or volume label syntax is incorrect C#OpenFileDialog:文件名,目录名称或卷标签语法不正确 - C# OpenFileDialog: The filename, directory name, or volume label syntax is incorrect 文件名、目录名或卷 label 语法不正确,c# - The filename, directory name, or volume label syntax is incorrect, c# 文件流 - 文件名、目录名或卷 label 语法不正确 - Filestream - The filename, directory name, or volume label syntax is incorrect 文件名、目录名或卷 label 不正确 - The filename, directory name or volume label is incorrect 文件名,目录名称或卷标签语法不正确。 (来自HRESULT的异常:0x8007007B) - The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B) 如何修复System.Net.WebException:'文件名,目录名或卷标签语法不正确 - How do I fix System.Net.WebException: 'The filename, directory name, or volume label syntax is incorrect protoc-gen-grpc 文件名、目录名或卷标语法不正确 - protoc-gen-grpc The filename, directory name, or volume label syntax is incorrect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM