<HTML>
<script language="vbscript" runat="server">
Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim arrSourcePath() As String = RegEx.Split(tbDirectorySorgente.Text, "/")
Dim lastFolder As String = arrSourcePath(UBound(arrSourcePath))
Dim sourcePath As String = Server.MapPath(tbDirectorySorgente.Text)
Dim destPath As String = Server.MapPath(tbDirectoryDestinazione.Text + "/" + lastFolder)
Try
CopyDirectory(sourcePath, destPath, True)
Catch exc As System.Exception
lbMessaggio.Text = exc.Message
lbMessaggio.Visible = True
End Try
End Sub
Private Sub CopyDirectory(sourcePath As String, destPath As String, overwrite As Boolean)
Dim sourceDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(sourcePath)
Dim destDir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(destPath)
If (sourceDir.Exists) Then
If Not (destDir.Exists) Then
destDir.Create()
End If
Dim file As System.IO.FileInfo
For Each file In sourceDir.GetFiles()
If (overwrite) Then
file.CopyTo(System.IO.Path.Combine(destDir.FullName, file.Name), True)
Else
If ((System.IO.File.Exists(System.IO.Path.Combine(destDir.FullName, file.Name))) = False) Then
file.CopyTo(System.IO.Path.Combine(destDir.FullName, file.Name), False)
End If
End If
Next
Dim dir As System.IO.DirectoryInfo
For Each dir In sourceDir.GetDirectories()
CopyDirectory(dir.FullName, System.IO.Path.Combine(destDir.FullName, dir.Name), overwrite)
Next
lbMessaggio.Text = "Cartella copiata"
lbMessaggio.Visible = True
Else
lbMessaggio.Text = "La cartela non esiste!"
lbMessaggio.Visible = True
End If
End Sub
</script>
<body>
<form runat="server" ID="Form1">
<table border="0" cellpadding="3" cellspacing="2">
<tr>
<td>Sorgente:</td>
<td><asp:TextBox Runat="server" ID="tbDirectorySorgente"></asp:TextBox></td>
</tr>
<tr>
<td>
Destinazione:</td>
<td><asp:TextBox Runat="server" ID="tbDirectoryDestinazione"></asp:TextBox></td>
</tr>
<tr>
<TD></TD>
<td colspan="2"><asp:Button Runat="server" ID="btnCopy" OnClick="Copy_Click" Text="CopiaCartella"></asp:Button></td>
</tr>
</table>
<br>
<asp:Label Runat="server" ID="lbMessaggio" Visible="False" ForeColor="#ff0000"></asp:Label>
</form>
</body>
</HTML>