简体   繁体   English

CopyFileEx与System.IO.File.Copy()

[英]CopyFileEx vs System.IO.File.Copy()

Currently having an odd scenario. 目前有一个奇怪的情况。

I manage a C# application to copy files from a server to a user's USB/SD Card. 我管理一个C#应用程序,将文件从服务器复制到用户的USB / SD卡。

I recently switched from System.IO.File.Copy(), to use a Pinvoke of CopyFileEx() that is in the kernal32. 我最近从System.IO.File.Copy()切换为使用kernal32中的PinFile的CopyFileEx()。

I'm not here to request code, my current wrapper and code works fine (except this case). 我不是在这里请求代码,我当前的包装器和代码都可以正常工作(这种情况除外)。

I did find out that the original file's attributes were not being copied, but i have resolved that. 我确实发现原始文件的属性没有被复制,但是我已经解决了。

CopyFileEx copies the files fine, but there are a few Siemens PLC SD cards that are not functioning as expected. CopyFileEx可以很好地复制文件,但是有一些Siemens PLC SD卡无法正常工作。 They appear to program fine, but the PLC never enters the run state. 它们似乎可以正常编程,但是PLC永远不会进入运行状态。 Oddly enough, a simple copy and paste from the file explorer works without any issues. 奇怪的是,从文件资源管理器进行的简单复制和粘贴可以正常工作。

Does anyone know if CopyFileEx changes the encoding of a file or the encryption possibly? 有谁知道CopyFileEx是否更改文件的编码或加密?

I compared the binary of the files before and after the copy process, and the files are identical. 我比较了复制过程前后文件的二进制文件,并且文件是相同的。 So, I am currently stumped. 所以,我目前很困惑。

The only copy flag I am currently using is COPY_FILE_RESTARTABLE, to get the status of the copy. 我当前使用的唯一复制标志是COPY_FILE_RESTARTABLE,以获取复制状态。 (Mainly necessary for larger files.) (主要用于较大的文件。)

Anyone have a similar experience? 任何人都有类似的经历吗?

Thanks, 谢谢,

-J -J

So it took a bit of digging and trial and error, but i figured out what was occurring. 因此,这需要花一些时间进行挖掘和反复试验,但我知道发生了什么。

The Copy functions are both fine. 复制功能都很好。 My earlier assumptions about the encoding and encryption were wrong, and the problem was more related to the files/folders on the Siemen's SD card. 我先前关于编码和加密的假设是错误的,并且问题更多与Siemen SD卡上的文件/文件夹有关。

Turned out that even though all of the files were copied correctly, there was an empty folder that was not being copied from the server to the SD card, which kept the PLC from programming properly. 事实证明,即使所有文件都已正确复制,仍然存在一个未从服务器复制到SD卡的空文件夹,这使PLC无法正确编程。

-J -J

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

相关问题 System.IO.File.Copy抛出System.UnauthorizedAccessException - System.IO.File.Copy throws System.UnauthorizedAccessException System.IO.File.Copy 错误,找不到文件 - System.IO.File.Copy Error with file not found C# System.IO.File.Copy 问题 - C# System.IO.File.Copy issue System.IO.File.Copy()产生System.IO.IOException:指定的网络名称不再可用 - System.IO.File.Copy() produces System.IO.IOException: The specified network name is no longer available 有关C#中System.IO.File.Copy和copy,xcopy,robocopy命令的一些问题 - Some questions about System.IO.File.Copy in C# and the copy, xcopy, robocopy commands 如何在System.IO.File.Copy期间避免Filewatcher锁定文件 - How to avoid Filewatcher lock file during System.IO.File.Copy .NET 4的System.IO.File.Copy和Unicode文件名的编码 - .NET 4's System.IO.File.Copy and encoding of Unicode file names 来自共享驱动器的 C# System.IO.File.Copy 在本地主机上工作,但在服务器上拒绝访问该路径 - C# System.IO.File.Copy from shared drive works on localhost but access to the path is denied on server 使用CopyFileEx复制另一个用户的加密文件 - Use CopyFileEx to copy encrypted file of another user 如何在没有CopyFile或CopyFileEx的情况下在Windows上复制大文件? - How can I copy a large file on Windows without CopyFile or CopyFileEx?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM