473,218 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 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 2500
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
0
by: Tess | last post by:
Hi, Long time reader, first time poster... Any help is appreciated. I have a few questions regarding Winform controls embedded within an html page. For more info please see the appendix. Now,...
4
by: John Blair | last post by:
Hi, Can anyone tell me how to make the Copy Project option work from within Vb.net - it fails on my PC with an error saying the new copy directory is marked as executable and i am not allowed to...
6
by: Wayne Wengert | last post by:
I am using VSNET 2003 to build an ASP.NET/VB set of pages. There are currently about a dozen aspx pages. When I make even a minor change to one page I currently rebuild the solution, copy the...
4
by: eholz1 | last post by:
Hello PHP group, I am trying to use the copy function to copy files from one directory to another. This does not seem to work for me. What am I missing? Below is the code I am using. ...
1
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again,...
1
by: ajc308 | last post by:
I'm attempting to sort the <file>s within each <directory> in my XML according to their file extension, then write out the resulting sorted data back to XML format. I had it working before, and when...
4
by: Masta | last post by:
Hello Group. I have a directory with 3000 ".jpg" named like this: 1234_01.jpg 1234_09.jpg 1234_11.jpg 1234_12.jpg 2341_01.jpg 2341_05.jpg
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.