Changing the current directory of a FileSystemObject file

When using FileSystemObject, you can refer to the directory with which the script was run using the path "." . Is it possible to change what FileSystemObject considers the current directory so that you can use "." . 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 for calling fso, so calling fso.GetFolder (".") Instead returns the backup directory?

+7
vbscript
source share
2 answers

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 hey, screenwriter! article on this topic: How to change the working script folder?

+11
source share

Not in general.

But why not find the current folder and save it:

 Set fso = CreateObject("Scripting.FileSystemObject") currentPath = fso.GetAbsolutePathName(".") 
+2
source share

All Articles