Solved

VB.net System.IO Copy all files from a folder to another folder

Posted on 2014-04-10
2
3,521 Views
Last Modified: 2014-04-10
Hi

What VB.net code would I use to move all the files in a folder to another folder using
System.IO?

Thanks
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39993328
        Imports System.Runtime.CompilerServices
	Imports System.IO
	 
	Module Extensions
	    <Extension()>
	    Public Sub MoveAllItemsTo(ByVal fromPathInfo As DirectoryInfo, ByVal toPath As String)
	        ''Create the target directory if necessary
	        Dim toPathInfo = New DirectoryInfo(toPath)
	        If (Not toPathInfo.Exists) Then
	            toPathInfo.Create()
	        End If
	        ''move all files
	        For Each file As FileInfo In fromPathInfo.GetFiles()
	            file.MoveTo(Path.Combine(toPath, file.Name))
	        Next
	        ''move all folders
	        For Each dir As DirectoryInfo In fromPathInfo.GetDirectories()
	            dir.MoveTo(Path.Combine(toPath, dir.Name))
	        Next
	    End Sub
	End Module

Open in new window


Call it like this:
	Dim fromDir = New DirectoryInfo("C:\dev\folder2")
	fromDir.MoveAllItemsTo("C:\dev\folder1")

Open in new window


http://www.dreamincode.net/forums/topic/197897-move-all-files-in-a-folder-to-another-folder/page__view__findpost__p__1157022?s=8cdb5dc39aa26dec600e40e0dc94b3c3
0
 

Author Closing Comment

by:Murray Brown
ID: 39993435
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question