Solved

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

Posted on 2014-04-10
2
3,038 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:murbro
2 Comments
 
LVL 26

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:murbro
ID: 39993435
Thanks very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now