使用FileSystemObject时,您可以使用路径“。”来引用运行脚本的目录。是否可以更改FileSystemObject认为当前目录的内容,以便您可以使用“。”。其他目录的路径语法?
示例:
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFolder(".") ' Returns the current directory
Set f2 = fso.GetFolder(".\backup") ' Returns the "backup" directory under the current directory
作为简化示例,是否有一种方法可以调用fso,以便fso.GetFolder(“。”)调用返回备份目录?
答案 0 :(得分:13)
您可以使用WshShell.CurrentDirectory
属性更改脚本的当前工作文件夹:
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = ".\backup"
这是一篇关于这个主题的 Hey,Scripting Guy!文章:How Can I Change the Working Folder of a Script?
答案 1 :(得分:2)
不一般。
但为什么不找到当前文件夹并存储它:
Set fso = CreateObject("Scripting.FileSystemObject")
currentPath = fso.GetAbsolutePathName(".")