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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
'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

'********************
 
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.
 
ah, good point, thanks.

Oenone said:
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.
 
Thanks for your reply. This certainly gives me somewhere to start.
--
Thanks


Oenone said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top