.CurrentDirectory - VBScript
Overview
The .CurrentDirectory
command in VB Script returns the full path of the current working directory. It allows scripts to access and manipulate files and directories within a specific location.
Syntax
.CurrentDirectory
Options/Flags
None
Examples
- Get Current Working Directory:
WScript.Echo .CurrentDirectory
- Change Current Working Directory:
.CurrentDirectory = "C:\Users\John\Documents"
- Create a File in Current Working Directory:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test.txt"
Common Issues
-
Permission Errors: If the script does not have sufficient permissions to access the current directory, it will raise an error.
-
Invalid Path: Providing an invalid path to
.CurrentDirectory
will result in an error.
Integration
.CurrentDirectory
can be used in conjunction with other VB Script commands, such as:
- Open a File:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile("test.txt")
- Iterate Files:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file In fso.GetFolder(.CurrentDirectory).Files
WScript.Echo file.Name
Next
Related Commands
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.GetFolder(path)
objFSO.GetFile(path)