471,066 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Copy Directory

I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore

Sep 25 '06 #1
12 2391
I found my error, it is for 2.0. I need to upgrade to 2.0 to get it to
work.

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #2
Scott,

You may or may not like this method, but I thought I'd post it anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #3
Or use just System.IO.Directory... Some of the 2.0 My features are just
wrappers around the .NET framework classes available elsewhere...

--
Patrice

"samoore33" <sa*******@gmail.coma écrit dans le message de news:
11**********************@m7g2000cwm.googlegroups.c om...
>I found my error, it is for 2.0. I need to upgrade to 2.0 to get it to
work.

samoore33 wrote:
>I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore

Sep 25 '06 #4
In the System.IO.Directory I can only find Move. I do not see where I
can copy a directory. The Move works, but it cuts the directory, it
does not copy it.

Scott

Patrice wrote:
Or use just System.IO.Directory... Some of the 2.0 My features are just
wrappers around the .NET framework classes available elsewhere...

--
Patrice

"samoore33" <sa*******@gmail.coma écrit dans le message de news:
11**********************@m7g2000cwm.googlegroups.c om...
I found my error, it is for 2.0. I need to upgrade to 2.0 to get it to
work.

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #5
I had used a bat file before, but had not thought of calling it through
code. Thanks for the idea.

Scott

Izzy wrote:
Scott,

You may or may not like this method, but I thought I'd post it anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #6
I am trying to use the XCOPY command in a batch file. This is what I am
trying to do.

@echo off

XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures

Pause

When I run this I get Invalid number of parameters?

Not sure what I am doing wrong here, please advise.

Scott

Izzy wrote:
Scott,

You may or may not like this method, but I thought I'd post it anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #7
Try this:

XCOPY C:\Pictures "C:\Documents and Settings\smoore\My
Documents\Pictures" /e /c /i /h /k

This issus is you didn't enclose the path with spaces in quatation
marks. Look at the link I sent too see what the switches mean.

Izzy
samoore33 wrote:
I am trying to use the XCOPY command in a batch file. This is what I am
trying to do.

@echo off

XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures

Pause

When I run this I get Invalid number of parameters?

Not sure what I am doing wrong here, please advise.

Scott

Izzy wrote:
Scott,

You may or may not like this method, but I thought I'd post it anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.
>
I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.
>
Thanks
>
Scott Moore
Sep 25 '06 #8
Thanks a lot Izzy, it is working now.

Izzy wrote:
Try this:

XCOPY C:\Pictures "C:\Documents and Settings\smoore\My
Documents\Pictures" /e /c /i /h /k

This issus is you didn't enclose the path with spaces in quatation
marks. Look at the link I sent too see what the switches mean.

Izzy
samoore33 wrote:
I am trying to use the XCOPY command in a batch file. This is what I am
trying to do.

@echo off

XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures

Pause

When I run this I get Invalid number of parameters?

Not sure what I am doing wrong here, please advise.

Scott

Izzy wrote:
Scott,
>
You may or may not like this method, but I thought I'd post it anyway.
>
You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:
>
http://www.computerhope.com/xcopyhlp.htm
>
You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.
>
By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.
>
Just a thought,
Izzy
>
samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.

Thanks

Scott Moore
Sep 25 '06 #9

Try This:

XCOPY C:\Pictures "C:\Documents and Settings\smoore\My Documents
\Pictures"
"samoore33" <sa*******@gmail.comwrote in
news:11*********************@k70g2000cwa.googlegro ups.com:
I am trying to use the XCOPY command in a batch file. This is what I
am trying to do.

@echo off

XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures

Pause

When I run this I get Invalid number of parameters?

Not sure what I am doing wrong here, please advise.

Scott

Izzy wrote:
>Scott,

You may or may not like this method, but I thought I'd post it
anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can
include hidden files, subdirectories, ignore errors, automatically
create subdirectories, turn message prompts off and a bunch of other
options. Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing
up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future
so code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else
has had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with
finding a way to copy a directory other then this information I am
finding on MSDN.

Thanks

Scott Moore
Sep 25 '06 #10
Why can't you write a simple routine to copy all the files in your source
directory to your new directory using the copy method of the file class.
--
Dennis in Houston
"samoore33" wrote:
Thanks a lot Izzy, it is working now.

Izzy wrote:
Try this:

XCOPY C:\Pictures "C:\Documents and Settings\smoore\My
Documents\Pictures" /e /c /i /h /k

This issus is you didn't enclose the path with spaces in quatation
marks. Look at the link I sent too see what the switches mean.

Izzy
samoore33 wrote:
I am trying to use the XCOPY command in a batch file. This is what I am
trying to do.
>
@echo off
>
XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures
>
Pause
>
When I run this I get Invalid number of parameters?
>
Not sure what I am doing wrong here, please advise.
>
Scott
>
Izzy wrote:
Scott,

You may or may not like this method, but I thought I'd post it anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing up.

By starting a new process you would be able to tell when the process
finishes. Additionally you could modify the .bat file in the future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN. The
only problem is that I can not figure out how to get the namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone else has
had experience with this, or knows of a different way to copy a
directory using VB.
>
I found ways to copy files, but not having a lot of luck with finding a
way to copy a directory other then this information I am finding on
MSDN.
>
Thanks
>
Scott Moore

Sep 26 '06 #11
I was thinking the same thing, why not just write a recursive function to do
it for you. It isn't difficult.

Hope this helps
Greetz, Peter

See sample code below.

Private Sub DirectoryCopy(ByVal src As String, ByVal dest As String)

If Not Directory.Exists(dest) Then
Directory.CreateDirectory(dest)
End If

If Directory.Exists(src) And Directory.Exists(dest) Then

Dim di As New DirectoryInfo(src)
Dim fsi As FileSystemInfo

For Each fsi In di.GetFileSystemInfos()
Try
Dim destName As String = Path.Combine(dest, fsi.Name)
If TypeOf fsi Is FileInfo Then
If fsi.Attributes = FileAttributes.ReadOnly Then
fsi.Attributes = FileAttributes.Normal
End If
File.Copy(fsi.FullName, destName, True)
Else
Directory.CreateDirectory(destName)
DirectoryCopy(fsi.FullName, destName)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Next

Else
MessageBox.Show("Source or target doesn't exist.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Dennis" <De****@discussions.microsoft.comschreef in bericht
news:D4**********************************@microsof t.com...
Why can't you write a simple routine to copy all the files in your source
directory to your new directory using the copy method of the file class.
--
Dennis in Houston
"samoore33" wrote:
Thanks a lot Izzy, it is working now.

Izzy wrote:
Try this:
>
XCOPY C:\Pictures "C:\Documents and Settings\smoore\My
Documents\Pictures" /e /c /i /h /k
>
This issus is you didn't enclose the path with spaces in quatation
marks. Look at the link I sent too see what the switches mean.
>
Izzy
>
>
samoore33 wrote:
I am trying to use the XCOPY command in a batch file. This is what I
am
trying to do.

@echo off

XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures

Pause

When I run this I get Invalid number of parameters?

Not sure what I am doing wrong here, please advise.

Scott

Izzy wrote:
Scott,
>
You may or may not like this method, but I thought I'd post it
anyway.
>
You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can
include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other
options.
Here is a complete list of switch options for xcopy:
>
http://www.computerhope.com/xcopyhlp.htm
>
You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing
up.
>
By starting a new process you would be able to tell when the
process
finishes. Additionally you could modify the .bat file in the
future so
code changes would not be necessary.
>
Just a thought,
Izzy
>
samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN.
The
only problem is that I can not figure out how to get the
namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone
else has
had experience with this, or knows of a different way to copy a
directory using VB.

I found ways to copy files, but not having a lot of luck with
finding a
way to copy a directory other then this information I am finding
on
MSDN.

Thanks

Scott Moore

Sep 26 '06 #12
Thanks for the code Peter, I'll archive it for later.

I think I still favor the xcopy method only because it's simple and
achives the same result.

Izzy
Peter Proost wrote:
I was thinking the same thing, why not just write a recursive function to do
it for you. It isn't difficult.

Hope this helps
Greetz, Peter

See sample code below.

Private Sub DirectoryCopy(ByVal src As String, ByVal dest As String)

If Not Directory.Exists(dest) Then
Directory.CreateDirectory(dest)
End If

If Directory.Exists(src) And Directory.Exists(dest) Then

Dim di As New DirectoryInfo(src)
Dim fsi As FileSystemInfo

For Each fsi In di.GetFileSystemInfos()
Try
Dim destName As String = Path.Combine(dest, fsi.Name)
If TypeOf fsi Is FileInfo Then
If fsi.Attributes = FileAttributes.ReadOnly Then
fsi.Attributes = FileAttributes.Normal
End If
File.Copy(fsi.FullName, destName, True)
Else
Directory.CreateDirectory(destName)
DirectoryCopy(fsi.FullName, destName)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Next

Else
MessageBox.Show("Source or target doesn't exist.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Dennis" <De****@discussions.microsoft.comschreef in bericht
news:D4**********************************@microsof t.com...
Why can't you write a simple routine to copy all the files in your source
directory to your new directory using the copy method of the file class.
--
Dennis in Houston
"samoore33" wrote:
Thanks a lot Izzy, it is working now.
>
Izzy wrote:
Try this:

XCOPY C:\Pictures "C:\Documents and Settings\smoore\My
Documents\Pictures" /e /c /i /h /k

This issus is you didn't enclose the path with spaces in quatation
marks. Look at the link I sent too see what the switches mean.

Izzy


samoore33 wrote:
I am trying to use the XCOPY command in a batch file. This is what I
am
trying to do.
>
@echo off
>
XCOPY C:\Pictures C:\Documents and Settings\smoore\My
Documents\Pictures
>
Pause
>
When I run this I get Invalid number of parameters?
>
Not sure what I am doing wrong here, please advise.
>
Scott
>
Izzy wrote:
Scott,

You may or may not like this method, but I thought I'd post it
anyway.

You could use xcopy in a .bat file to copy the directory from one
location to another. Using different switches for xcopy you can
include
hidden files, subdirectories, ignore errors, automatically create
subdirectories, turn message prompts off and a bunch of other
options.
Here is a complete list of switch options for xcopy:

http://www.computerhope.com/xcopyhlp.htm

You could call this .bat file using
System.Diagnostics.Process.Start([Path To .bat File])
I think you should be able to hide the command window from showing
up.

By starting a new process you would be able to tell when the
process
finishes. Additionally you could modify the .bat file in the
future so
code changes would not be necessary.

Just a thought,
Izzy

samoore33 wrote:
I found a real nice article on how to copy a directory on MSDN.
The
only problem is that I can not figure out how to get the
namespace
Microsoft.VisualBasic.MyServices. I wanted to know if anyone
else has
had experience with this, or knows of a different way to copy a
directory using VB.
>
I found ways to copy files, but not having a lot of luck with
finding a
way to copy a directory other then this information I am finding
on
MSDN.
>
Thanks
>
Scott Moore
>
>
Sep 26 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Antonio Lopez Arredondo | last post: by
reply views Thread by Tess | last post: by
6 posts views Thread by Wayne Wengert | last post: by
4 posts views Thread by eholz1 | last post: by
1 post views Thread by ajc308 | last post: by
4 posts views Thread by Masta | last post: by
reply views Thread by leo001 | last post: by

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.