vi scrivo tutto il programma, tanto è breve, così mi dite anche se ci possono essere modifiche da fare:
codice:
Imports System.IO
Module modAvvio
Dim strPrg As String = "JavaUpdate"
Sub Main()
Dim arrFile As String(), arrPath As String()
arrPath = PrendiFileTesto()
If arrPath Is Nothing Then
End
Exit Sub
End If
For i As Integer = 0 To arrPath.GetUpperBound(0)
arrFile = arrPath(i).Split(";")
If arrFile(0).Trim.Length > 0 Then
For y As Int32 = 0 To arrFile.GetUpperBound(0)
arrFile(y) = arrFile(y).Replace("%ProgramFiles%", Environment.GetEnvironmentVariable("ProgramFiles"))
arrFile(y) = arrFile(y).Replace("%SystemRoot%", Environment.GetEnvironmentVariable("SystemRoot"))
Next
Select Case arrFile.GetUpperBound(0)
Case 0
If Directory.Exists(arrFile(0)) = False Then
Directory.CreateDirectory(arrFile(0))
End If
Case 1
If arrFile(0).Substring(arrFile(0).Length - 1) = Path.DirectorySeparatorChar And arrFile(1).Substring(arrFile(1).Length - 1) = Path.DirectorySeparatorChar Then
Call CreaCopiaDirectory(arrFile(0), arrFile(1))
Else
Call CreaCopiaFile(arrFile(0), arrFile(1))
End If
Case Else
Call Errore("Impossibile controllare il file: " & arrFile(0), strPrg)
End Select
End If
Next
Application.Exit()
End Sub
Function PrendiFileTesto() As String()
Dim arrTesto As String(), SR As StreamReader, strTesto As String, strFile As String
arrTesto = Nothing
Try
strFile = "\\Server_linux\Utile\Spool\StampeJava\impofile.txt"
SR = New StreamReader(strFile)
Catch ex1 As Security.SecurityException
Call Errore(ex1.Message, strPrg)
Return arrTesto
Catch ex As FileNotFoundException
Dim strMsg As String
strMsg = "File delle impostazioni di " & strPrg & " non trovato o connessione alla rete inesistente"
Call Errore(strMsg, strPrg)
Return arrTesto
End Try
strTesto = SR.ReadToEnd
SR.Close()
SR = Nothing
arrTesto = strTesto.Split(Environment.NewLine)
For i As Integer = 0 To arrTesto.GetUpperBound(0)
arrTesto(i) = arrTesto(i).Replace(vbLf, "")
Next
Return arrTesto
End Function
Sub CreaCopiaDirectory(ByVal strDirO As String, ByVal strDirC As String)
Dim DirO As DirectoryInfo, DirC As DirectoryInfo, swFind As Boolean
DirO = New DirectoryInfo(strDirO)
DirC = New DirectoryInfo(strdirC)
If DirO.Exists = False Then
Call Errore("La cartella " & strDirO & "non esiste... chiamare Programmatori!!", strPrg)
Else
If DirO.Equals(DirC) Then
Call Errore(DirO.FullName & ": la path di origile e la path di destinazione sono identiche", strPrg)
Else
Call CopiaDirectory(strDirO, strDirC)
End If
End If
End Sub
Public Sub CopiaDirectory(ByVal Origine As String, ByVal Destinazione As String)
Dim CorrDirectory As DirectoryInfo = New DirectoryInfo(Origine)
Dim OFile As FileInfo, SubDir As DirectoryInfo, strPath As String
If Directory.Exists(Destinazione) = False Then
Directory.CreateDirectory(Destinazione)
End If
For Each SubDir In CorrDirectory.GetDirectories()
strPath = Path.Combine(Destinazione, SubDir.Name)
CopiaDirectory(SubDir.FullName, strPath)
Next
For Each OFile In CorrDirectory.GetFiles()
strPath = Path.Combine(Destinazione, OFile.Name)
Call CreaCopiaFile(OFile.FullName, strPath)
Next
End Sub
Sub CreaCopiaFile(ByVal strFileO As String, ByVal strFileC As String)
Dim strMsg As String, FileC As FileInfo, FileO As FileInfo
FileO = New FileInfo(strFileO)
FileC = New FileInfo(strFileC)
If FileO.Exists = False Then
Call Errore("Il file " & strFileO & " non esiste... chiamare programmatori!!", strPrg)
Else
If strFileO.Equals(strFileC, StringComparison.CurrentCultureIgnoreCase) Then
strMsg = strFileO & ": Il file da controllare e il file originale hanno la stessa path"
Call Errore(strMsg, strPrg)
Else
If FileC.Exists = False Then
FileO.CopyTo(strFileC)
Else
If FileO.LastWriteTime > FileC.LastWriteTime Then
FileC.Delete()
FileO.CopyTo(strFileC)
End If
End If
End If
End If
FileC = Nothing
FileO = Nothing
End Sub
End Module
Module modAvvisi
Sub Errore(ByVal strMsg As String, ByVal strTitle As String)
MessageBox.Show(strMsg, strTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
End Module
per ora c'è la replace in quanto io non sò usare le RegEx....
mi studio la cosa e poi lo innesto nel programma....