【发布时间】:2021-07-04 23:22:13
【问题描述】:
如果文件夹已经存在,我正在研究一种方法来覆盖它,并确认。这是我的代码(以及我坚持的部分):
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”是我需要帮助的地方。谢谢!
【问题讨论】:
-
您是否尝试过查看the official documentation 而不仅仅是好奇? - “如果指定的文件夹已经存在则出错”.
-
是的,实际上。我已经查了几十次这个问题,检查了任何官方文档,以及如何创建文件夹的示例,但我总是得到“CopyFolder”结果,它对我不起作用。
-
当你说覆盖文件夹是打算删除所有现有的内容?
-
是的。但是我找不到任何帖子。