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

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.75 out of 5)
 

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

Your email address will not be published.