覆盖 visual basic 脚本中的文件夹?

overwrite folders in visual basic script?

我正在研究一种覆盖文件夹(如果已存在)并确认的方法。这是我的代码(连同我坚持的部分):

Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
Set network = CreateObject("WScript.Network")
username = network.userName
userprofile = shell.ExpandEnvironmentStrings("%userprofile%")

If fso.FolderExists(userprofile + "\foldername") = False Then
    fso.CreateFolder(userprofile & "\foldername")
    End If
If fso.FolderExists(userprofile + "\foldername") = True Then
    overwrite = msgbox("The directory that foldername uses(" & userprofile + "\foldername) is unavailable. Overwrite?",4+16+4096,"")
        if overwrite = vbYes then
            overwrite2 = msgbox("THIS IS YOUR LAST WARNING. Any files in " & userprofile + "\foldername will be PERMANENTLY LOST. Continue?",4+16+4096,"")
                if overwrite2 = vbYes then
                    'overwriting folder goes here
                    End If
                if overwrite2 = vbNo then
                    End If
        if overwrite = vbNo then
        End If

overwriting folder goes here”是我需要帮助的地方。谢谢!

当你说覆盖文件夹时是指删除所有现有内容吗?如果可以,能不能先删除文件夹再重新创建?

if overwrite2 = vbYes then
    strFolderPath = userprofile & "\foldername"
    fso.DeleteFolder strFolderPath, true
    fso.CreateFolder(strFolderPath)
    End If