[VB.NET]problema con copydirectory

martedì 23 luglio 2013 - 09.34
Tag Elenco Tags  VB.NET

rerupippo Profilo | Newbie

Buongiorno a tutti,

ho un problema con la funzione Copydirectory e non riesco a risolvere, a meno di usare il vecchio comando dos XCOPY.
La mia necessità è quella di copiare una cartella (files e sottocartelle comprese) in un'altra cartelle. Per queso ho provato con questa riga di codice
My.Computer.FileSystem.CopyDirectory("\\srvfs1\ff7$\Vault\Prova-1\", "\\srvfs1\ff7$\Vault\Prova-2\", True) ma non funziona.
Ho letto che non funziona se il percorso inizia con \\, avete un'alternativa da propormi ?

grazie mille a tutti
Rodolfo


PS
stesso problema com Move.
R.Z.

Vinsent Profilo | Senior Member

Penso perchè è un' unita di rete e dovresti prima aggiungerla assegnandogli la classica lettera alle "risorse del computer".
Non ho molta esperienza...e non so consigliarti un metodo diretto....però se con i comandi DOS funge puoi usare CMD con la classe Process passandogli comando e parametri.

rerupippo Profilo | Newbie

grazie per il tuo interessamento, ho cmq risolto con questa funzioncina un pochino rivista :

Public Function DuplicoCartella(ByVal PathS As String, ByVal PathD As String) As Boolean
Try

Dim dirInfo As New System.IO.DirectoryInfo(PathS)
Dim fsInfo As System.IO.FileSystemInfo

'If Not System.IO.Directory.Exists(strDest) Then
' System.IO.Directory.CreateDirectory(strDest)
'End If

System.IO.Directory.CreateDirectory(PathD & "\" & UltimaCartella(PathS))
PathD = PathD & "\" & UltimaCartella(PathS)

For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = System.IO.Path.Combine(PathD, fsInfo.Name)
If TypeOf fsInfo Is System.IO.FileInfo Then
System.IO.File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDirectory(fsInfo.FullName, strDestFileName, True)
End If
Next
DuplicoCartella = True
frmPrincipale.tmrChk.Enabled = True

Catch ex As Exception
ScriviLog("Errore nella duplicazione della cartella nel Vault (" & ex.Message & ") " & Now & " [Riga errore : " & Erl() & "]")
DuplicoCartella = False
frmPrincipale.tmrChk.Enabled = True
End Try
End Function
Public Function CopyDirectory(ByVal Src As String, ByVal Dest As String, Optional ByVal bQuiet As Boolean = False) As Boolean
If Not Directory.Exists(Src) Then
Throw New DirectoryNotFoundException("The directory " & Src & " does not exists")
End If
If Directory.Exists(Dest) AndAlso Not bQuiet Then
If MessageBox.Show("directory " & Dest & " already exists." & vbCrLf & _
"If you continue, any files with the same name will be overwritten", _
"Continue?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button2) = DialogResult.Cancel Then Exit Function
End If

'add Directory Seperator Character (\) for the string concatenation shown later
If Dest.Substring(Dest.Length - 1, 1) <> Path.DirectorySeparatorChar Then
Dest += Path.DirectorySeparatorChar
End If
If Not Directory.Exists(Dest) Then Directory.CreateDirectory(Dest)
Dim Files As String()
Files = Directory.GetFileSystemEntries(Src)
Dim element As String
For Each element In Files
If Directory.Exists(element) Then
'if the current FileSystemEntry is a directory,
'call this function recursively
CopyDirectory(element, Dest & Path.GetFileName(element), True)
Else
'the current FileSystemEntry is a file so just copy it
File.Copy(element, Dest & Path.GetFileName(element), True)
End If
Next
Return True
End Function


grazie e buona giornata
Rodolfo
R.Z.
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5