使用Windows 8.1和VBScript我需要在APPDATA中创建一个文件夹。这是我的代码,我收到错误Path Not Found

时间:2015-04-08 15:29:36

标签: vbscript scripting

尝试使用Windows 8.1在\ username \ appdata \ local \中创建一个文件夹,但我的代码是找不到错误路径。请帮忙!

Option Explicit

Dim oShell, oEnv, oFS, strDirectory, LocalAppData, wshshell

Set oShell = CreateObject("wscript.Shell")
set oFS = CreateObject("scripting.FileSystemObject")
Set oEnv = oShell.Environment("Process")
set wshshell = createobject("wscript.shell")

strDirectory = oEnv("USERPROFILE") & "\My Documents\MyConnect"
If Not oFS.FolderExists(strDirectory) Then oFS.CreateFolder(strDirectory)

我认为我的错误就在这里

LocalAppData = wshshell.expandenvironmentstrings("%APPDATA%") &           "\Local\MyConnectSettings"
If Not oFS.FolderExists (LocalAppData)  Then oFS.CreateFolder (LocalAppData)

1 个答案:

答案 0 :(得分:0)

.CreateFolder不会创建中间目录(mkdir除外)。因此,请确保%appdata%\local存在。