.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

  1. Get Current Working Directory:
WScript.Echo .CurrentDirectory
  1. Change Current Working Directory:
.CurrentDirectory = "C:\Users\John\Documents"
  1. Create a File in Current Working Directory:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test.txt"

Common Issues

  1. Permission Errors: If the script does not have sufficient permissions to access the current directory, it will raise an error.

  2. 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:

  1. Open a File:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.OpenTextFile("test.txt")
  1. Iterate Files:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file In fso.GetFolder(.CurrentDirectory).Files
    WScript.Echo file.Name
Next
  • Set objFSO = CreateObject("Scripting.FileSystemObject")
  • objFSO.GetFolder(path)
  • objFSO.GetFile(path)