Debbo fare il backup completa di una cartella. Ho fatto del codice che sembra funzionare. Dato che sono molto arruginito in questo campo, chiedo se qualcuno possa controllarlo e darmi dei suggerimenti.![]()
codice:Module Module1 Sub Main() CancellaCopia("c:\tmp\d1", "d:\prova") Console.WriteLine("") Console.Write("Premi un tasto per uscire...") : Console.ReadKey() End Sub Private Sub CancellaCopia(ByVal pathIn As String, ByVal pathOut As String) pathOut = Path.Combine(pathOut, Path.GetFileName(pathIn)) Cancella(pathOut) Copia(pathIn, pathOut) End Sub Private Sub Cancella(ByVal path As String) If Not Directory.Exists(path) Then Return For Each fname As String In Directory.GetFiles(path) If CBool(File.GetAttributes(fname) And FileAttributes.ReadOnly) Then File.SetAttributes(fname, FileAttributes.Archive) End If File.Delete(fname) Console.WriteLine("cancellato: " & fname) Next For Each subdir As String In Directory.GetDirectories(path) Cancella(subdir) Next Directory.Delete(path) End Sub Private Sub Copia(ByVal pathIn As String, ByVal pathOut As String) Directory.CreateDirectory(pathOut) For Each fname As String In Directory.GetFiles(pathIn) Dim fcname As String = Path.Combine(pathOut, Path.GetFileName(fname)) File.Copy(fname, fcname) Console.WriteLine(fcname) Next For Each subdir As String In Directory.GetDirectories(pathIn) Dim dcname As String = Path.Combine(pathOut, Path.GetFileName(subdir)) Copia(subdir, dcname) Next End Sub End Module

Rispondi quotando
