この再帰的なprocで試すことができます。
Public Shared Function moveDirectoryContent(srcDir As String, destDir As String) as Integer
Dim countFile As Integer = 0
If (Not Directory.Exists(destDir)) Then
Directory.CreateDirectory(destDir)
End If
Dim listFiles() As String = Directory.GetFileSystemEntries(srcDir)
Dim curFile As String
For Each curFile In listFiles
If Directory.Exists(curFile) Then
countFile = countFile + moveDirectoryContent(curFile, Path.Combine(destDir, Path.GetFileName(curFile)))
Else
Dim dstFile = Path.Combine(destDir, Path.GetFileName(curFile))
If File.Exists(dstFile) Then
dstFile = GetUniqueName(dstFile)
End If
File.Copy(curFile, dstFile)
File.Delete(curFile)
countFile = countFile + 1
End If
Next
Return countFile
End Function
Public Shared Function GetUniqueName(srcFile as String) as String
Dim uFile As String = Path.GetFileNameWithoutExtension(srcFile)
Dim ext as String = Path.GetExtension(srcFile)
Dim cnt As Integer = 0
Dim uniqueText = string.Format("_{0}_00", DateTime.ToDay.ToString("yyyy_MM_dd"))
While(File.Exists(uFile + uniqueText + ext))
cnt = cnt + 1
uniqueText = string.Format("_{0}_{1:D2}", DateTime.ToDay.ToString("yyyy_MM_dd"), cnt)
End While
Return Path.GetDirectoryName(srcFile) + "\" + uFile + uniqueText + ext
End Function
このように電話します
numMoved = moveDirectoryContent("C:\temp", "C:\temp2")
宛先フォルダをソースフォルダ内に置くことはできないことに注意してください...(チェックは実行されません)