更改FileSystemObject的当前目录

dla*_*nod 8 vbscript

使用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
Run Code Online (Sandbox Code Playgroud)

作为简化示例,是否有一种方法来调用fso,以便fso.GetFolder(".")调用返回备份目录?

Hel*_*len 13

您可以使用WshShell.CurrentDirectory属性更改脚本的当前工作文件夹:

Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = ".\backup"
Run Code Online (Sandbox Code Playgroud)

这是一个嘿,脚本专家!关于这个主题的文章:如何更改脚本的工作文件夹?