473,671 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to move a directory between two different volumes

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
Nov 20 '05 #1
3 4176
One solution is to map a drive and use the IO Filesystem classes to copy the
data. Ther's probably a slicker way to do it, but this will work. In the
example below, the letter H: is mapped to a URN resource newpublic on the
server \\tower1. This drive letter can then be used as a local drive letter
would be.

IE.
Try
System.Diagnost ics.Process.Sta rt("net", "use h:
\\tower1\newpub lic")
Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
Regards - OHM ( Terry Burns )

"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

Nov 20 '05 #2
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

Nov 20 '05 #3
"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message news:<ut******* *******@TK2MSFT NGP12.phx.gbl>. ..
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


thx greg,

your example helped me a lot!!
Just what I searched for

Karel
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1939
by: Kamus of Kadizhar | last post by:
Thanks to everyone on this list. I now have a functioning piece of python code!! :-)) Now I'm trying to clean it up. I have the same (or similar) lines repeated several times: shutil.copy2(newArrivalsDir+'/'+movie,archivesDir) thumb = string.replace(movie,'.avi','.jpg') shutil.copy2(newArrivalsDir+'/tn/'+thumb,archivesDir+'/tn/')
1
7760
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ---------------------------------------------------------------------------- ----------------- import re, os, time, shutil os.chdir(os.environ+os.environ+"\\Desktop") DESKTOP = os.listdir(os.environ+os.environ+"\\Desktop")
3
8836
by: andrew | last post by:
I do not understand how this function should work. It seems to be different than when I drag a folder ... error message: Cannot create a file when that file already exists. c:\atest has subfolder btest which has subfolder ctest plus a single file. ( c:\atest\btest\ctest\test.txt ) c:\aatest is an empty folder. If I drag atest to aatest, I will have c:\aatest\atest\btest\ctest\test.txt But as noted using the function as below wont...
1
4072
by: rv | last post by:
I am developing an ASP.NET website with C#, VS 2003 and Framework 1.1. For some reason every time I execute a Directory.Move command, the next command takes 10-20 seconds to execute. Has anyone else experienced this? I just want to rename a directory, so if there is a better way I am all ears. Thanks
8
2387
by: Ron Vecchi | last post by:
I know this has been asked before but I out of all the posts I've read regarding using Directory.Move and then the application restarting itself I have found no answer except that Sessions are buggy or that you should create a new folder then copy the content of the old into it and then delete the old one...pretty lame for such a simple IO action. Can microsoft give an answer to how to fix this or is this just a know bug... that will...
15
22308
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system. I can do this with the glob() function, but I can't seem to put in a directory other than one within the webroot. For example, I can only put "/uploads" and not "/Volumes/jray/Pictures...". Any ideas how to get around this? If I can't use the...
3
3275
by: Arpan | last post by:
A Form has a FileUpload, 2 Buttons & a TextBox web server controls. Using the FileUpload control, I want to give users the provision to move & delete files that DO NOT exist in C:\Inetpub\wwwroot (i.e. the root directory). This is the code: <script runat="server"> Sub MoveFile(ByVal obj As Object, ByVal ea As EventArgs) File.Move(fudFileSource.FileName, txtFileDest.Text) 'File.Move("F:\4.jpg", "C:\4.jpg") End Sub
8
4075
by: Lee | last post by:
guys, I have a project need to move more than 100,000 records from one database table to another database table every week. Currently, users input date range from web UI, my store procedure will take those date ranges to INSERT records to a table in another database, then delete the records, but it will take really long time to finish this action (up to 1 or 2 hours). My question is if there is some other way I should do to speed up...
1
2043
by: Madhu Harchandani | last post by:
Hello i am working in a project in which i am using xnat technology in that data is entered through xml files only i need to enter 1000 records .so it is very cumbersome to create 1000 xml files So i need a simple way so that i can create and insert 1000 records in xnat database this is the xml file which i want to generate again and again with some different values Plz could someone helps me get over this problem ...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2810
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.