Copy, Create, Delete, and Rename a Directory/Folder using the MY Interface

This source code works for VB 2005, VB 2008, Visual Basic 2010, and higher.


'
'Copy, Create, Delete, and Renaming a Directory.
Dim dir AsString = "c:\Directory"'

'
'Create a directory with the path and name specified in the dir string variable.
My.Computer.FileSystem.CreateDirectory(dir)

'
'New directory with the contents of the dir path copied to it.
My.Computer.FileSystem.CopyDirectory(dir, "c:\Directory Copied")

'
'Rename the original directory that is specified in the dir variable to the new directory name.
My.Computer.FileSystem.RenameDirectory(dir, "Directory Renamed") 

'
'Delete both the Copy Directory and the Renamed Directory from the harddrive.
My.Computer.FileSystem.DeleteDirectory("c:\Directory Copied", FileIO.DeleteDirectoryOption.DeleteAllContents) 

My.Computer.FileSystem.DeleteDirectory("Directory Renamed", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.DoNothing)

8 thoughts on “Copy, Create, Delete, and Rename a Directory/Folder using the MY Interface

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.