groovy 压缩包含正在使用的文件的目录

发布于 2024-07-29 02:28:09 字数 256 浏览 2 评论 0原文

我正在尝试在常规程序中压缩整个目录。 我已经使用内置的 ant 目标来压缩目录,通常这是有效的,除了有时使用 2-3 个文件,我不关心,但 zip 代码实际上因此中止 - 关于如何修复的任何想法这?

谢谢!

代码:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/temp.zip", 
    basedir: "c:/Temp/"
) 

I am trying to zip an entire directory in a groovy program. I have used the built in ant target to zip the directory and normally this works, except that sometimes 2-3 files are in use which I don't care about but the zip code actually aborts because of that - any ideas on how to fix this?

Thanks!

Code:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/temp.zip", 
    basedir: "c:/Temp/"
) 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

刘备忘录 2024-08-05 02:28:09

因此,我当前使用的解决方案是忽略正在使用的文件,因为它们始终相同...我将它们放在排除子句中,请参见下文:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/Temp.zip", 
    basedir: "c:/Temp",
    level: 9,
    excludes: "**/file1.dat, **/file2.dat, **/file3.dat"
)

我仍然愿意接受更好的解决方案!

So the solution that I am currently using is the ignore the files that are in use since they are always the same... I put them in an exclude clause, see below:

def ant = new AntBuilder() 
ant.zip(
    destfile: "C:/Temp.zip", 
    basedir: "c:/Temp",
    level: 9,
    excludes: "**/file1.dat, **/file2.dat, **/file3.dat"
)

I am still open to a better solution!

缪败 2024-08-05 02:28:09

我不熟悉 Groovy 或 AntBuilder,但我相信您可以使用 VShadow 程序创建目录的卷影副本,并从那里进行备份。

创建驱动器 C: 的卷影副本

vshadow -p C:

将卷影副本装载为新驱动器号:

vshadow -el=ShadowCopyId,Z:

驱动器 Z: 将成为 C: 的副本,这将允许您打开文件。

完成后,删除卷影副本:

vshadow -ds=ShadowCopyId

I'm not familiar with Groovy or AntBuilder, but I believe you can use the VShadow program to create a volume shadow copy of the directory, and do the backup from there.

Create a volume shadow copy of drive C:

vshadow -p C:

Mount the shadow copy as a new drive letter:

vshadow -el=ShadowCopyId,Z:

The drive Z: will then be a copy of C: which should allow you to open the files.

And when you're done, delete the shadow copy:

vshadow -ds=ShadowCopyId

故事与诗 2024-08-05 02:28:09

没有“更好”的解决方案,因为主要问题似乎是您在压缩其工作文件时使用应用程序(Firefox)。

您可以使用 ZipOutputStream 等实现您自己的 zip 机制,但只要您不关闭 Firefox 或在压缩文件之前定期检查所有文件是否已锁定,您就会遇到同样的问题。

There is no "better" solution, as the main issue seems to be that you're using your Application (Firefox) while zipping its working files.

You could implement your own zip mechanism, using ZipOutputStream and so on, but you'll have the same issue as long as you don't either close Firefox or check periodically that all the files are lock free before zipping them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文