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

问题描述

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

dispatchQueue.global(qos: .background).async {
    self?.completeOnboarding( completion: { (success) in
      dispatchQueue.main.async {
        if success {
         print("success")
        } else {
         print("Failed")
        }
     }
 })

func completeOnboarding(completion: @escaping(Bool) -> Void){

   // has network post operation
    classRegistration() {(success) in
      if !success {
        completion(false)
        return
      }
    }

    // has network post operation
    classLocation() { (success) in
      if !success {
        completion(false)
        return
      }
    }
  completion(true)
}

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?","") if overwrite2 = vbYes then 'overwriting folder goes here End If if overwrite2 = vbNo then End If if overwrite = vbNo then End If ”是我需要帮助的地方。谢谢!

解决方法

当你说覆盖文件夹是打算删除所有现有内容时?如果是这样,您能否先删除该文件夹,然后重新创建它?

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