Export (0) Print
Expand All

How to: Move a Directory in Visual Basic

The My.Computer.FileSystem.MoveDirectory Method can be used to move directories.

If an attempt is made to move a directory inside a directory that does not exist, the target directory will be created.

If overwrite is True and the destination directory already exists, the new files will be added to the already existing files in the directory. Files in the destination directory will be overwritten if the source directory contains files with the same name.

To move a directory

  • Use the MoveDirectory method to move a directory, specifying the source and target directories. The following example moves Dir1 inside Dir2.

    My.Computer.FileSystem.MoveDirectory("C:\Dir1", "C:\Dir2")
    

To move a directory and overwrite existing directories

  • Use the MoveDirectory method to move a directory, specifying the source and target directories. The following example moves Dir1 inside Dir2, adding its files to the existing files if the destination directory already exists.

    My.Computer.FileSystem.MoveDirectory("C:\Dir1", "C:\Dir2", True)
    

The following conditions may cause an exception:

Community Additions

ADD
Show:
© 2014 Microsoft