静默解压文件,无对话框覆盖 [英] Unzip file silently and without dialog box to overwrite

查看:91
本文介绍了静默解压文件,无对话框覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 vbscript 一个接一个地解压缩多个文件.

I am working on vbscript to unzip the multiple files one after another.

我正在使用以下代码

Dim folder(3)
folder(0) = "UBO90R1"
folder(1) = "UBO90R2"
folder(2) = "UBO100R1"
folder(3) = "UBO100R2"

For i = 0 To 3
    unzip_Source = "D:\Autobackup\" & folder(i) & ".zip"
    unzip_destination = "D:\Autobackup_unzip\" & folder(i) &"\"

    Call ExtractFilesFromZip(unzip_Source,unzip_destination)

    WScript.Echo "unzip Finished"
Next

Sub ExtractFilesFromZip(pathToZipFile, dirToExtractFiles)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    pathToZipFile = fso.GetAbsolutePathName(pathToZipFile)
    dirToExtractFiles = fso.GetAbsolutePathName(dirToExtractFiles)

    If (Not fso.FileExists(pathToZipFile)) Then
        WScript.Echo "Zip file does not exist: " & pathToZipFile
        Exit Sub
    End If

    If Not fso.FolderExists(dirToExtractFiles) Then
        WScript.Echo "Directory does not exist: " & dirToExtractFiles
        Exit Sub
    End If

    dim sa  : Set sa = CreateObject("Shell.Application")
    Dim zip : Set zip = sa.NameSpace(pathToZipFile)
    Dim d   : Set d = sa.NameSpace(dirToExtractFiles)

    d.CopyHere zip.items, 4

    Do Until zip.Items.Count <= d.Items.Count
        WScript.Sleep(200)
    Loop
End Sub

目前我遇到的问题是,如果文件夹或文件已经存在,则它会向用户打开对话框以选择任何选项覆盖、保留两个文件等.

The Problem currently I have that if the folder or file is already exist than it open the dialog to the user to select any option Overwrite, keep both file etc.

如果我从代码中更改以下行

If I change the following line from the code

d.CopyHere zip.items, 4
'Integer 4 didn't show the progress bar

d.CopyHere zip.items, 16
'Integer 16 overwrite the existing file but it shows the progress bar.

我想在没有任何对话框和进度条的情况下覆盖现有文件.

I would like to overwrite the existing file without any dialog box and without any progress bar.

PS:从 此处.

推荐答案

查看帮助,我们会找到以下内容.

Looking at help we would find the follwing.

Type: FILEOP_FLAGS

Flags that control the file operation. This member can take a combination of the following flags.

FOF_ALLOWUNDO

Preserve undo information, if possible.

Prior to Windows Vista, operations could be undone only from the same process that performed the original operation.

In Windows Vista and later systems, the scope of the undo is a user session. Any process running in the user session can undo another operation. The undo state is held in the Explorer.exe process, and as long as that process is running, it can coordinate the undo functions.

If the source file parameter does not contain fully qualified path and file names, this flag is ignored.

FOF_CONFIRMMOUSE

Not used.

FOF_FILESONLY

Perform the operation only on files (not on folders) if a wildcard file name (.) is specified.

FOF_MULTIDESTFILES

The pTo member specifies multiple destination files (one for each source file in pFrom) rather than one directory where all source files are to be deposited.

FOF_NOCONFIRMATION

Respond with Yes to All for any dialog box that is displayed.

FOF_NOCONFIRMMKDIR

Do not ask the user to confirm the creation of a new directory if the operation requires one to be created.

FOF_NO_CONNECTED_ELEMENTS

Version 5.0. Do not move connected files as a group. Only move the specified files.

FOF_NOCOPYSECURITYATTRIBS

Version 4.71. Do not copy the security attributes of the file. The destination file receives the security attributes of its new folder.

FOF_NOERRORUI

Do not display a dialog to the user if an error occurs.

FOF_NORECURSEREPARSE

Not used.

FOF_NORECURSION

Only perform the operation in the local directory. Do not operate recursively into subdirectories, which is the default behavior.

FOF_NO_UI

Windows Vista. Perform the operation silently, presenting no UI to the user. This is equivalent to FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR.

FOF_RENAMEONCOLLISION

Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists at the destination.

FOF_SILENT

Do not display a progress dialog box.

FOF_SIMPLEPROGRESS

Display a progress dialog box but do not show individual file names as they are operated on.

FOF_WANTMAPPINGHANDLE

If FOF_RENAMEONCOLLISION is specified and any files were renamed, assign a name mapping object that contains their old and new names to the hNameMappings member. This object must be freed using SHFreeNameMappings when it is no longer needed.

FOF_WANTNUKEWARNING

Version 5.0. Send a warning if a file is being permanently destroyed during a delete operation rather than recycled. This flag partially overrides FOF_NOCONFIRMATION.

这篇关于静默解压文件,无对话框覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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