FolderItem.InvokeVerb("Delete") 没有确认 [英] FolderItem.InvokeVerb("Delete") without confirmation

查看:59
本文介绍了FolderItem.InvokeVerb("Delete") 没有确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个工具,该工具将自动存档服务器上的旧日志文件并从存档中删除太旧的文件.而且有问题.我需要使用 powershell 从 .ZIP 存档中删除单个文件,所以我这样做:

I'm trying to write a tool that will automatically archivate old log files on server and delete too old files from archive. And there are problem. I need to delete single file from .ZIP archive with powershell, so I do:

$testFile = "C:\test_logs\FirstEntry.zip"
$sh = New-Object -com shell.application
$zip = $sh.NameSpace($testFile)
$item = $zip.Items() | Select-Object -index 3
$item.InvokeVerb("Delete")

但是我在尝试以这种方式删除文件时收到确认窗口.是否可以在没有确认的情况下使用 InvokeVerb(ex) 删除文件?或者有什么其他方法可以用 powershell 做到这一点?

But I receive confirmation window when trying to delete file this way. Is it possible to delete file with InvokeVerb(ex) without confirmation? Or any other way to do it with powershell?

推荐答案

我找到的最简单的方法是:

The easiest way I found is:

$tmp_dir = $env:Temp + "\log_archivation_temp\"
$sh = New-Object -com shell.application
$tmp = $sh.NameSpace($tmp_dir)
$tmp.MoveHere($item.Path)
Remove-Item $tmp_dir

所以我只是将旧文件从存档移动到临时文件夹,然后将其删除.

So I just move old files from archive to temporary folder, then delete it.

这篇关于FolderItem.InvokeVerb("Delete") 没有确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆