vbscript - 覆盖Visual Basic脚本中的文件夹?
问题描述
如果文件夹已经存在,我正在研究一种覆盖文件夹的方法,并确认。这是我的代码(以及我坚持的部分):
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
推荐阅读
- css - Flexdashboard中tabset的文本样式使用css
- python - 将张量流张量转换为张量列表时出错
- c - 使用格式说明符 %d 和 %u 将 ~0 类型转换为 (unsigned int) 和 (unsigned short) 对 short 产生相同的结果,但对 int 产生不同的结果
- c# - 为什么在 Visual Studio 2019 中发布时出现 Build 错误
- javascript - 将 UTM 参数附加到我当前的 URL
- javascript - 单击提交按钮后如何重置输入值?
- r - 查找每个组内最近的地理点
- django-rest-framework - 从viewsets.ViewSet访问当前用户
- ruby - ruby 包已加载但不起作用
- c++ - c++ Windows 10 获取已连接客户端的 Ip