我创建了一个powershell脚本,用于侦听要在桌面上创建的文件。 如果符合特定条件,该文件将被立即删除。 我使用了Remove-Item $path ,其中$path是我想要删除的文件的路径。 问题是窗口仍然增加,并继续在桌面上显示该项目。 该文件绝对不存在,因为试图操作它将导致“无法找到此项目”或“文件不存在”错误。 通过“右键点击=>刷新”手动刷新桌面将导致项目被删除。
删除桌面上的项目后,是否有办法强制桌面刷新? 否则,是否有替代方法来删除文件以防止它被添加到第一个地方?
I have created a powershell script that listens for files to be created on the desktop. The file is immediately deleted if it meets certain criteria. I used Remove-Item $path where $path is the path to the file I want to delete. The problem is that windows still adds, and continues to show the item on the desktop. The file is definitely not there, since attempting to manipulate it will result in a 'Could not find this item', or 'File does not exist' error. Manually refreshing the desktop via 'Right Click => Refresh' will cause the item to be removed.
Is there a way to force the desktop to refresh after deleting an item on it? Otherwise, is there an alternate method to delete the file to prevent it being added in the first place?
最满意答案
您可以使用Shell32.dll中的SHChangeNotify
你在PowerShell.com中有一个函数
ou can use the SHChangeNotify from Shell32.dll
You've got a function in PowerShell.com
更多推荐
发布评论