PC Review


Reply
Thread Tools Rate Thread

Copy directory

 
 
Regan Hurd
Guest
Posts: n/a
 
      6th Sep 2003
Is there any way to copy a directory with the system.io
namespace? Thanks
 
Reply With Quote
 
 
 
 
One Handed Man [ OHM ]
Guest
Posts: n/a
 
      6th Sep 2003
You have to code it yourself, see various examples on th google search




"Regan Hurd" <(E-Mail Removed)> wrote in message
news:294001c3747a$5aeb5470$(E-Mail Removed)...
> Is there any way to copy a directory with the system.io
> namespace? Thanks



 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      6th Sep 2003
If you want to copy an entire directory structure, including all sub-files
and their sub-folders and henceforth, then you'll have to write a recursive
method.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"


"Regan Hurd" <(E-Mail Removed)> wrote in message
news:294001c3747a$5aeb5470$(E-Mail Removed)...
> Is there any way to copy a directory with the system.io
> namespace? Thanks



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Sep 2003
Hello,

"Regan Hurd" <(E-Mail Removed)> schrieb:
> Is there any way to copy a directory with the system.io
> namespace?


Untested:

http://www.bubble-media.com/cgi-bin/...es/000026.html

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      8th Sep 2003
Hi Regan,

It's not too easy, because you have to run a recursive routine to get all
the subs and the files they contain.

I wrote several routines in an effort to use this concept to save .net
solutions in order to provide backup copies. I won't bore you with all the
details; instead, below is the code that makes it happen, which I'm sure
you'll be able to follow along and work with:
Imports System.IO

Public Class Form1

Inherits System.Windows.Forms.Form

Public selectedsubs As New ArrayList()

Public subs2 As New ArrayList()



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dirinfo As New DirectoryInfo("c:\vsapps\")

For Each dirinfo In dirinfo.GetDirectories()

solutionsbox.Items.Add(dirinfo.Name)

Next

End Sub

Private Sub saveit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles saveit.Click

Dim dirsys As Directory

Dim copytopath As String

Dim dirfullpath As String

Dim solselectionsarray As String

Dim mdirectory As DirectoryInfo

Dim mfile As FileInfo

Dim dfile As File()

Dim destinationfile As String

Dim solutionsboxfp As New ArrayList()

Dim shortstring, stringfront As String

Dim i, j, startpos As Integer

Me.Cursor = Cursors.WaitCursor

For Each solselectionsarray In solutionsbox.CheckedItems

selectedsubs.Add("c:\vsapps\" & solselectionsarray)

Next

subs2.Clear()

For i = 0 To selectedsubs.Count - 1

mdirectory = New DirectoryInfo(selectedsubs(i))

listdirectories(mdirectory)

Next

For j = 0 To subs2.Count - 1

mdirectory = New DirectoryInfo(subs2(j))

startpos = InStrRev(mdirectory.FullName, "\")

shortstring = Mid(mdirectory.FullName, startpos + 1)

stringfront = Mid(mdirectory.FullName, 11)

If dirsys.Exists("c:\dotnetsource\" & stringfront) Then

Else

dirsys.CreateDirectory("c:\dotnetsource\" & stringfront)

End If

For Each mfile In mdirectory.GetFiles

destinationfile = "c:\dotnetsource\" & stringfront & "\" & mfile.Name

File.Copy(mfile.FullName, destinationfile, True)

Next

Next

Me.Cursor = Cursors.Default

Application.Exit()



End Sub

Sub listdirectories(ByVal thedirectory As DirectoryInfo)

Dim tempdir As DirectoryInfo

subs2.Add(thedirectory.FullName)

For Each tempdir In thedirectory.GetDirectories()

listdirectories(tempdir)

Next

End Sub

End Class



HTH,

Bernie Yaeger


"Regan Hurd" <(E-Mail Removed)> wrote in message
news:294001c3747a$5aeb5470$(E-Mail Removed)...
> Is there any way to copy a directory with the system.io
> namespace? Thanks



 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      8th Sep 2003
Hi Regan, Bernie,

Don't forget to add appropriate Exception handling. Do you hate it when
Shell says can't copy this file and aborts the whole operation? I certainly
do.

Regards,
Fergus


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      8th Sep 2003
Hello,

"Bernie Yaeger" <(E-Mail Removed)> schrieb:
> Public Class Form1
>
> Inherits System.Windows.Forms.Form
>
> Public selectedsubs As New ArrayList()
>
> Public subs2 As New ArrayList()
>
>
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> Dim dirinfo As New DirectoryInfo("c:\vsapps\")
>
> For Each dirinfo In dirinfo.GetDirectories()
>
> solutionsbox.Items.Add(dirinfo.Name)
>
> Next
>
> End Sub
>
> Private Sub saveit_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles saveit.Click
>
> Dim dirsys As Directory
>
> Dim copytopath As String
>
> Dim dirfullpath As String
>
> Dim solselectionsarray As String
>
> Dim mdirectory As DirectoryInfo
>
> Dim mfile As FileInfo
>
> Dim dfile As File()
>
> Dim destinationfile As String
>
> Dim solutionsboxfp As New ArrayList()
>
> Dim shortstring, stringfront As String
>
> Dim i, j, startpos As Integer
>
> Me.Cursor = Cursors.WaitCursor
>
> For Each solselectionsarray In solutionsbox.CheckedItems
>
> selectedsubs.Add("c:\vsapps\" & solselectionsarray)
>
> Next
>
> subs2.Clear()
>
> For i = 0 To selectedsubs.Count - 1
>
> mdirectory = New DirectoryInfo(selectedsubs(i))
>
> listdirectories(mdirectory)
>
> Next
>
> For j = 0 To subs2.Count - 1
>
> mdirectory = New DirectoryInfo(subs2(j))
>
> startpos = InStrRev(mdirectory.FullName, "\")
>
> shortstring = Mid(mdirectory.FullName, startpos + 1)
>
> stringfront = Mid(mdirectory.FullName, 11)
>
> If dirsys.Exists("c:\dotnetsource\" & stringfront) Then
>
> Else
>
> dirsys.CreateDirectory("c:\dotnetsource\" & stringfront)
>
> End If
>
> For Each mfile In mdirectory.GetFiles
>
> destinationfile = "c:\dotnetsource\" & stringfront & "\" & mfile.Name
>
> File.Copy(mfile.FullName, destinationfile, True)
>
> Next
>
> Next
>
> Me.Cursor = Cursors.Default
>
> Application.Exit()
>
>
>
> End Sub
>
> Sub listdirectories(ByVal thedirectory As DirectoryInfo)
>
> Dim tempdir As DirectoryInfo
>
> subs2.Add(thedirectory.FullName)
>
> For Each tempdir In thedirectory.GetDirectories()
>
> listdirectories(tempdir)
>
> Next
>
> End Sub
>
> End Class


Please paste the code into notepad before pasting it into a posting.
This will preserve indentation.

--
Herfried K. Wagner
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to copy files names in a column from one directory to another directory VBA Paul B Microsoft Excel Programming 4 10th Nov 2008 01:54 AM
Would like to write batch file to copy all TXT files in a given directory and all subdirectories to a single target directory. Rob Windows XP General 5 20th Aug 2007 02:42 PM
I want to copy all files in one directory to another directory =?Utf-8?B?RnJhbms=?= Microsoft VB .NET 5 8th Nov 2005 02:21 AM
VB.Net Copy Project fails because copy directory is marked executable. John Blair Microsoft ASP .NET 4 12th Jan 2005 02:24 AM
Copy all files and sub-directory under a specific directory Phil Microsoft Access 1 20th Dec 2003 11:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 AM.