This is what I used (Visual Basic)
[VB]
Imports System
Imports System.IO
Imports System.IO.IsolatedStorage
Private Sub Copy_Info()
Dim strFolders() As String = IO.Directory.GetDirectories(Me.txtSourceLocation.Text)
Dim NewPath As String = strFullAccountTarget
Dim strFileExt As String
Dim strFileExt1 As String
Get all the files in the main Directory
Dim MainFiles() As String = IO.Directory.GetFiles(Me.txtSourceLocation.Text)
Dim FileToCopy As String
For each file in Source Directory copy to Target Directory
For Each FileToCopy In MainFiles
Dim f As IO.FileInfo = New IO.FileInfo(FileToCopy)
strFileExt = Microsoft.VisualBasic.Left(f.Name, (Len(f.Name) - 3))
strFileExt = Microsoft.VisualBasic.Right(strFileExt, 1)
If strFileExt = "h" Then
strFileExt = Microsoft.VisualBasic.Left(f.Name, (Len(f.Name) - 4))
strFileExt = Microsoft.VisualBasic.Right(strFileExt1, 1)
End If
If strFileExt = "." Then
IO.File.Copy(FileToCopy, NewPath & f.Name)
Else
IO.File.Copy(FileToCopy, NewPath & f.Name & f.Extension)
End If
IO.File.Copy(FileToCopy, NewPath & f.Name & f.Extension)
Next
Get all the SubFolders and Copy to next directory
Dim Path As String
For Each Path In strFolders
Dim di As New IO.DirectoryInfo(Path)
Dim SubFile As String = NewPath & di.Name & "\"
IO.Directory.CreateDirectory(SubFile)
Get all the files in the Sub folders
Dim FilePath As String
For Each FilePath In IO.Directory.GetFiles(di.FullName)
Dim fi As New IO.FileInfo(FilePath)
strFileExt1 = Microsoft.VisualBasic.Left(fi.Name, (Len(fi.Name) - 3))
strFileExt1 = Microsoft.VisualBasic.Right(strFileExt1, 1)
If strFileExt1 = "h" Then
strFileExt1 = Microsoft.VisualBasic.Left(fi.Name, (Len(fi.Name) - 4))
strFileExt1 = Microsoft.VisualBasic.Right(strFileExt1, 1)
End If
If strFileExt1 = "." Then
IO.File.Copy(FilePath, SubFile & fi.Name)
Else
IO.File.Copy(FilePath, SubFile & fi.Name & fi.Extension)
End If
IO.File.Copy(FilePath, SubFile & fi.Name & fi.Extension)
Next
Next
End Sub
[/VB]
I hope this helps. The reason I did a check on the file extension was that the program was putting the file extension twice on the files.