SetWorkingDir

AutoHotkey GUI

SetWorkingDir

Changes the script's current working directory.

SetWorkingDir, DirName

Parameters

DirName

The name of the new working directory, which is assumed to be a subfolder of the current %A_WorkingDir% if an absolute path isn't specified.

ErrorLevel

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

Remarks

The script's working directory is the default directory that is used to access files and folders when an absolute path has not been specified. In the following example, the file My Filename.txt is assumed to be in %A_WorkingDir%: FileAppend, A Line of Text, My Filename.txt.

A script's initial working directory is determined by how it was launched. For example, if it was run via shortcut -- such as on the Start Menu -- its working directory is determined by the "Start in" field within the shortcut's properties.

To make a script unconditionally use its own folder as its working directory, make its first line the following:

SetWorkingDir %A_ScriptDir%

Once changed, the new working directory is instantly and globally in effect throughout the script. All interrupted, paused, and newly launched threads are affected, including Timers.

Related

%A_WorkingDir%, %A_ScriptDir%, FileSelectFolder

Example

SetWorkingDir %A_ScriptDir%
SetWorkingDir, D:\My Folder\Temp