关闭应用程序后复制文件
复制文件的方法有多种:使用 TFileStream
、使用 TShFileOpStruct
、Windows.CopyFile
(至少我发现的是这样的)。< br> 当我使用我提到的方法之一开始文件复制时,我的应用程序冻结(仅文件复制窗口处于活动状态),并且当我关闭应用程序时,文件复制也被取消。
是否可以复制/移动文件,以便该过程不依赖于我的应用程序?
我的意思是,如何开始复制/移动操作然后关闭我的应用程序并且复制/移动将保留?
There are several ways to copy files: using TFileStream
, using TShFileOpStruct
, Windows.CopyFile
(at least that's what I've found).
When I start file copying using one of the ways I've mentioned my application freezes (only file copying window is active) and when I close my application, file copying is also canceled.
Is it possible to copy/move files so that the process won't depend on my application?
I mean, how can I start copy/move operation an then close my application and the copying/moving will remain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅@David 帖子,另外......有一次我记得我有类似的要求,我必须在应用程序关闭时在网络驱动器上制作一些数据的备份副本。我只是在 OnClose 处理程序中将 CloseAction 设置为 caHide,因此保持应用程序加载,直到运行副本的线程完成,然后它调用 ExitProcess() 最终消失。
这种简单方法的问题在于,用户可能会在旧版本仍在进行备份时尝试启动应用程序的另一个副本 - 这会导致大问题。我们刚刚在用户手册中添加了一段内容来涵盖这一点,但有一些更好的解决方案,例如。强制新实例在启动时等待旧实例完成,效果会更好。大卫运行单独进程的解决方案在这方面似乎更优越,mod。任何新应用程序实例的副本和启动之间的任何“干扰”。
See @David post, plus.. The one time I can remember where I had a similar requirement, I had to make a backup copy of some data on a network drive on app close. I just set the CloseAction to caHide in the OnClose handler and so kept the app loaded until the thread running the copy was complete, whereupon it called ExitProcess() to finally die off.
The issue with this simple approach is that the user could attempt to start another copy of the app while the old one was still doing the backups - this caused big problems. We just added a paragraph in the user manual to cover that, but some better solution, eg. forcing new instances to wait on startup until any old ones have finished, would have been better. David's solution of running a separate process would seem to be superior in that respect, mod. any 'interference' between the copy and the startup of any new app instance.
即使在关闭应用程序后也可以复制到另一个位置,您可以尝试此操作
使用批处理文件...
您可以在批处理文件中执行并让您的应用程序关闭,批处理文件将继续将文件复制到目的地..
您可以使用 shellexecute 来
复制包含以下内容的文件夹里面的更多文件夹尝试这个
检查这些链接也
为日期编写批处理文件基于文件复制
直接复制批处理文件命令
将文件复制到另一个位置的批处理文件
for copying to another location even after you have closed your application, you can try this
using
batch
files...this you can execute in a batch file and let you application close, the batch file will continue copying the files to the destination..
you can use shellexecute to
to copy folders which contains more folders inside try this
check these links also
writing a batch file fordate based file copying
directo copy batch file command
batch file to copy files to another location
我所知道的所有文件复制 API 都在调用进程中执行。这意味着当您终止进程时,文件复制也将终止。
因此,为了确保应用程序关闭后文件复制继续进行,您需要从不同的进程运行文件复制。您可以创建一个简单的进程来完成这项工作,并向其传递命令行参数以指定要复制的文件。
如果您只想在复制过程中解冻主应用程序,那么您可以创建一个单独的线程来执行文件复制。
All of the file copying APIs that I know of execute in the calling process. This means that when you terminate the process, the file copying will be terminated also.
So, in order to ensure that the file copying continues after your application closes, you would need to run the file copy from a different process. You could create a simple process that did the work and pass it command line arguments to specify which files to copy.
If you just want to unfreeze your main application whilst the copy is in progress, then you could create a separate thread to perform the file copy.