?
Solved

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

Posted on 2014-04-10
2
Medium Priority
?
3,669 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

800 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