473,416 Members | 1,888 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,416 software developers and data experts.

I want to copy all files in one directory to another directory

I'm using VB .NET and I'm finding that CopyTo will not help me copy all the
files in one directory to antoher directory at one time. Which command (if
that's the word) do I use to copy ALL the files at one to another directory?
--
Thanks (Novice)
Nov 23 '05 #1
5 15070
'fromDir is the source folder and toDir is dest folder

Dim f() As String = Directory.GetFiles(fromDir)
For i As Integer = 0 To UBound(f)
File.copy(f(i), toDir & "\" & fileNameWithoutThePath(f(i)))
Next

'********************
Public Function fileNameWithoutThePath(ByVal b As String) As String
Dim j As Int16

j = Convert.ToInt16(b.LastIndexOf("\"))
Return b.Substring(j + 1)

End Function

'********************

"Frank" wrote:
I'm using VB .NET and I'm finding that CopyTo will not help me copy all the
files in one directory to antoher directory at one time. Which command (if
that's the word) do I use to copy ALL the files at one to another directory?
--
Thanks (Novice)

Nov 23 '05 #2
chad wrote:
[...]
Public Function fileNameWithoutThePath(ByVal b As String) As String

[...]

Easier to use System.IO.Path.GetFileName(), which does the same thing
without requiring you to implement it yourself.

--

(O)enone

Nov 23 '05 #3
ah, good point, thanks.

"Oenone" wrote:
chad wrote:
[...]
Public Function fileNameWithoutThePath(ByVal b As String) As String

[...]

Easier to use System.IO.Path.GetFileName(), which does the same thing
without requiring you to implement it yourself.

--

(O)enone

Nov 23 '05 #4
Thanks. I appreciate the response. This should give me somewhere to start.
--
Thanks
"chad" wrote:
'fromDir is the source folder and toDir is dest folder

Dim f() As String = Directory.GetFiles(fromDir)
For i As Integer = 0 To UBound(f)
File.copy(f(i), toDir & "\" & fileNameWithoutThePath(f(i)))
Next

'********************
Public Function fileNameWithoutThePath(ByVal b As String) As String
Dim j As Int16

j = Convert.ToInt16(b.LastIndexOf("\"))
Return b.Substring(j + 1)

End Function

'********************

"Frank" wrote:
I'm using VB .NET and I'm finding that CopyTo will not help me copy all the
files in one directory to antoher directory at one time. Which command (if
that's the word) do I use to copy ALL the files at one to another directory?
--
Thanks (Novice)

Nov 23 '05 #5
Thanks for your reply. This certainly gives me somewhere to start.
--
Thanks
"Oenone" wrote:
chad wrote:
[...]
Public Function fileNameWithoutThePath(ByVal b As String) As String

[...]

Easier to use System.IO.Path.GetFileName(), which does the same thing
without requiring you to implement it yourself.

--

(O)enone

Nov 23 '05 #6

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...
6
by: Peter Row | last post by:
Hi, Can someone give me a set of steps for an ASP.NET project (well actually its just a VB.NET class DLL that implements HttpHandler) that will work when moved to another developers machine? ...
5
by: Verane | last post by:
Hi, I have read the thread named "Could not copy temporary files to the output directory" on this newsgroup. And I have the same symptoms on my machine. But I didn't find any solution suitable for...
12
by: samoore33 | last post by:
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...
14
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class...
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,...
4
by: GS | last post by:
from the online help, looks like to code step by step to copy content of directory to another whereas I can use online line code for directory move or delete. I am using 2005 express .net 2 I did...
7
by: prasadrallabandi | last post by:
Hello every one, my question is how to copy from one directory to another directory (Windows)? clearly: c:\perl> present working directory I have to copy all the text files(*.txt), lets...
2
by: foss | last post by:
hi all, I am not able to copy file from a directory in the server to another directory. Here, the source is outside the web root directory and the destination is inside the web root directory. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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...

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.