I ended up mapping a drive like OHM recommended. Here is some code from a
console app of mine to get you started... (it also creates a trace file to
let you know when something goes wrong)
HTH,
Greg
------------------------------------------
Option Strict On
Imports System.IO
Module Module1
Sub Main()
Dim Source As String = "Z:\ilc\tem p"
Dim Dest As String = "N:\temp\" & Year(Today) & Right("0" &
Month(Today), 2) & Right("0" & Day(Today), 2)
System.IO.Direc tory.CreateDire ctory(Dest)
'get the log file name
Dim logFileName As String = Dest & "\trace.log "
'open the log file
Dim fileLog As StreamWriter = File.CreateText (logFileName)
'define the log file trace listener
Dim logListener As TextWriterTrace Listener = New
TextWriterTrace Listener(fileLo g)
'add the new trace listener to the collection of listeners
Trace.Listeners .Add(logListene r)
Dim consoleListener As MyTrace = New MyTrace
Trace.Listeners .Add(consoleLis tener)
'make sure that we actually write the data out
Trace.AutoFlush = True
RecursiveCopyFi les(Source, Dest, True)
Trace.WriteLine ("Finished." )
logListener.Flu sh()
logListener.Clo se()
System.Environm ent.ExitCode = 0
End Sub
' Recursively copy all files and subdirectories from the
' specified source to the specified destination.
Private Function RecursiveCopyFi les( _
ByVal sourceDir As String, _
ByVal destDir As String, _
ByVal bTop As Boolean) As Boolean
Dim i As Integer
Dim posSep As Integer
Dim sDir As String
Dim aDirs() As String
Dim sFile As String
Dim aFiles() As String
Dim ok As Boolean = True
' Add trailing separators to the supplied paths if they don't exist.
If Not
sourceDir.EndsW ith(System.IO.P ath.DirectorySe paratorChar.ToS tring()) Then
sourceDir &= System.IO.Path. DirectorySepara torChar
End If
If Not
destDir.EndsWit h(System.IO.Pat h.DirectorySepa ratorChar.ToStr ing()) Then
destDir &= System.IO.Path. DirectorySepara torChar
End If
Trace.WriteLine ("Inspecting folder " & sourceDir)
Try
' Get a list of directories from the current parent.
aDirs = System.IO.Direc tory.GetDirecto ries(sourceDir)
For i = 0 To aDirs.GetUpperB ound(0)
' Get the position of the last separator in the current
path.
posSep = aDirs(i).LastIn dexOf("\")
' Get the path of the source directory.
sDir = aDirs(i).Substr ing((posSep + 1), aDirs(i).Length -
(posSep + 1))
' Create the new directory in the destination directory.
System.IO.Direc tory.CreateDire ctory(destDir + sDir)
' Since we are in recursive mode, copy the children also
ok = True
ok = RecursiveCopyFi les(aDirs(i), (destDir + sDir), False)
If ok Then
Try
Trace.WriteLine ("Deleting " & destDir + sDir)
System.IO.Direc tory.Delete(des tDir + sDir)
Catch ex As Exception
Trace.WriteLine ("Error deleting " & destDir + sDir)
Trace.WriteLine (ex.Message)
ok = False
End Try
End If
Next
Catch ex As Exception
Trace.WriteLine ("Error reading directory " & sourceDir)
End Try
' Get the files from the current parent.
aFiles = System.IO.Direc tory.GetFiles(s ourceDir)
' Copy all files.
For i = 0 To aFiles.GetUpper Bound(0)
' Get the position of the trailing separator.
posSep = aFiles(i).LastI ndexOf("\")
' Get the full path of the source file.
sFile = aFiles(i).Subst ring((posSep + 1), aFiles(i).Lengt h -
(posSep + 1))
Try
' Copy the file.
Trace.WriteLine ("Copying " & aFiles(i))
System.IO.File. Copy(aFiles(i), destDir + sFile)
Try
' Delete the file.
Trace.WriteLine ("Deleting " & aFiles(i))
System.IO.File. Delete(aFiles(i ))
Catch ex As Exception
Trace.WriteLine ("Error deleting " & aFiles(i))
Trace.WriteLine (ex.Message)
ok = False
End Try
Catch ex As Exception
Trace.WriteLine ("Error copying " & aFiles(i))
Trace.WriteLine (ex.Message)
ok = False
End Try
Next i
If Not bTop Then
Try
Trace.WriteLine ("Deleting folder " & sourceDir)
System.IO.Direc tory.Delete(sou rceDir)
Catch ex As Exception
Trace.WriteLine ("Error deleting folder " & sourceDir)
Trace.WriteLine (ex.Message)
ok = False
End Try
End If
End Function
End Module
' disallow inheriting this class
Public NotInheritable Class MyTrace
Inherits TraceListener
' disallow instantiation
Public Sub New()
MyBase.New()
End Sub
<Conditional("T RACE")> _
Public Overloads Overrides Sub Write(ByVal message As String)
Console.Write(m essage)
End Sub
<Conditional("T RACE")> _
Public Overloads Overrides Sub WriteLine(ByVal message As String)
Console.WriteLi ne(message)
End Sub
End Class
"Karel" <ka***********@ informat.be> wrote in message
news:68******** *************** ***@posting.goo gle.com...
Hello,
I have a VB.NET application where I want to move directories over a
network.
I tried this with system.io.direc tory.move, but that doesn't work over
different volumes.
Has anyone a sollution for this problem?
thx
Karel