更改 FileSystemObject 的当前目录 [英] Changing the current directory of a FileSystemObject
问题描述
使用 FileSystemObject 时,您可以使用路径."引用运行脚本的目录.是否可以更改 FileSystemObject 认为当前目录的内容,以便您可以使用."其他目录的路径语法?
示例:
Set fso = CreateObject("Scripting.FileSystemObject")Set f1 = fso.GetFolder(".") ' 返回当前目录Set f2 = fso.GetFolder(".\backup") ' 返回当前目录下的backup"目录
举个简单的例子,是否有一种方法可以调用 fso,以便 fso.GetFolder(".") 调用返回备份目录?
您可以使用 WshShell.CurrentDirectory
属性:
Dim oShell : Set oShell = CreateObject("WScript.Shell")oShell.CurrentDirectory = ".\backup"
这里有一篇嘿,脚本专家!关于这个主题的文章:如何更改脚本的工作文件夹?>
When using a FileSystemObject you can reference the directory the script was run from by using the path ".". Is it possible to change what the FileSystemObject thinks is the current directory so you can use the "." path syntax for other directories?
Example:
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
As a simplified example, is there a method to call on fso so that the fso.GetFolder(".") call returns the backup directory instead?
You can change the current working folder for your script using the WshShell.CurrentDirectory
property:
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = ".\backup"
And here's a Hey, Scripting Guy! article on the subject: How Can I Change the Working Folder of a Script?
这篇关于更改 FileSystemObject 的当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!