DirMove()

Auto Hotkey

DirMove

Moves a folder along with all its sub-folders and files. It can also rename a folder.

DirMove Source, Dest , Flag
Exmaple: DirMove("C:\MyFolder","C:\MyNewFolder")
DirMove, Source, Dest [, Flag]
Exmaple: DirMove, C:\MyFolder, C:\MyNewFolder

Parameters

Source

Name of the source directory (with no trailing backslash), which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. For example: C:\My Folder

Dest

The new path and name of the directory (with no trailing baskslash), which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. For example: D:\My Folder. Note: Dest is the actual path and name that the directory will have after it is moved; it is not the directory into which Source is moved (except for the known limitation mentioned below).

Flag

(options) Specify one of the following single characters:

0 (default): Do not overwrite existing files. The operation will fail if Dest already exists as a file or directory.

1: Overwrite existing files. However, any files or subfolders inside Dest that do not have a counterpart in Source will not be deleted. Known limitation: If Dest already exists as a folder and it is on the same volume as Source, Source will be moved into it rather than overwriting it. To avoid this, see the next option.

2: The same as mode 1 above except that the limitation is absent.

R: Rename the directory rather than moving it. Although renaming normally has the same effect as moving, it is helpful in cases where you want "all or none" behavior; that is, when you don't want the operation to be only partially successful when Source or one of its files is locked (in use). Although this method cannot move Source onto a different volume, it can move it to any other directory on its own volume. The operation will fail if Dest already exists as a file or directory.

ErrorLevel

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

Remarks

DirMove moves a single folder to a new location. To instead move the contents of a folder (all its files and subfolders), see the examples section of FileMove.

If the source and destination are on different volumes or UNC paths, a copy/delete operation will be performed rather than a move.

Related

DirCopy, FileCopy, FileMove, FileDelete, File-loops, DirSelect, SplitPath

Example

DirMove, C:\My Folder, D:\My Folder  ; Move to a new drive.
DirMove, C:\My Folder, C:\My Folder (renamed), R  ; Simple rename.
DirMove, C:\My Folder, C:\New Location\My Folder, R  ; Folders can be "renamed into" another location as long as it's on the same volume.