VB.NET déplacer des fichier dans un autre répertoire en récursif
Bonjour!
J'ai un dossier contenant plusieurs documents xml. Mon programme fonctionne en batch (pas d'IHM).
Il parse tout les documents présent dans le dossier Documents et après traitement, il transfère le fichier dans le dossier backUp si il n'y a pas d'erreur sinon dans celui ToCorrect. Il ne déplace rien et j'ai compris pourquoi mais je ne vois pas comment régler le problème.
voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| Private Sub ImportDoc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'variable pour le dossier
Dim sfiles As String()
Dim nbFiles As String
Dim i As Integer
sFiles = Directory.GetFiles(documents)
nbFiles = Directory.GetFiles(documents).Length()
'Variable compteur d'erreur
Dim errorCount As Integer = 0
'Vérifie si le dossier est vide
If nbFiles = 0 Then
writeFile(vbDate & "No document today!")
writeFile("-----------------------------------------------------------------------------------------")
Else : writeFile(vbDate)
For i = 0 To nbFiles - 1
Dim pathfile As String = sfiles(i)
Dim pathfileBackUp As String = sfiles(i)
Dim pathfileToCorrect As String = sfiles(i)
treatXMLDocuments(pathfile, errorCount)
writeFile("***********************************************")
If errorCount = 0 Then
'Envoye le document dans le dossier Back-up
File.Move(pathfile, pathfileBackUp)
Else 'Envoye le document dans toCorrect
File.Move(pathfile, pathfileToCorrect)
End If
Next
writeFile("-----------------------------------------------------------------------------------------")
End If
Catch ex As Exception
writeFile(ex.ToString)
End Try
End Sub |
Et aussi, je dois tester si un tag XML existe ou pas.
voici un extrait de mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.Load(pathfile)
'Traite la partie Header
Dim element As XmlNodeList
element = xmlDoc.DocumentElement.GetElementsByTagName("HEADER")
Dim node, nodeChild As XmlNode
For Each node In element
For Each nodeChild In node.ChildNodes
Select Case nodeChild.LocalName
Case "DOCUMENTID"
documentID = nodeChild.InnerText
Case "INVOICENR"
invoiceNr = nodeChild.InnerText
Case "INTERNAL_REFERENCE"
internalRef = nodeChild.InnerText
Case "JOURNAL"
journal = nodeChild.InnerText
Case "CUSTOMERNUMBER"
customerNumber = nodeChild.InnerText
Case "INVOICEDATE"
invoiceDate = nodeChild.InnerText
Case "VATRATE"
vatRate = nodeChild.InnerText
Case "DUEPERIOD"
duePeriod = nodeChild.InnerText
Case "DUE_DATE"
dueDate = nodeChild.InnerText
Case "INVOICETYPE"
invoiceType = nodeChild.InnerText
Case "FINANCIAL_TYPE"
financialType = nodeChild.InnerText
Case "ATTENTIONOF"
attentionOf = nodeChild.InnerText
Case "COMPANY"
company = nodeChild.InnerText
Case "DEPARTMENT"
department = nodeChild.InnerText
Case "INVOICECURRENCY"
invoiceCurrency = nodeChild.InnerText
Case "EXCHANGE_RATE"
exchangeRate = nodeChild.InnerText
Case "INVOICEDESCRIPTION"
invoiceDescription = nodeChild.InnerText
Case "TOTALAMOUNT"
totalAmount = nodeChild.InnerText
Case "TOTALAMOUNTVAT"
totalAmountVat = nodeChild.InnerText
Case "VAT_NO"
vatNo = nodeChild.InnerText
Case "VAT_CODE"
vatCode = nodeChild.InnerText
Case "POSTINGDATE"
postingDate = nodeChild.InnerText
Case "GENERAL_LEDGER"
generalLedger = nodeChild.InnerText
Case "SOURCE"
source = nodeChild.InnerText
Case "INTERNAL_NO"
internalNo = nodeChild.InnerText
Case "COMPANYNR"
companyNr = nodeChild.InnerText
Case "INVOICE_NO_SUPPLIER"
invoiceNoSupplier = nodeChild.InnerText
Case "CREATE_TIMESTAMP"
createTimestamp = nodeChild.InnerText
End Select
Next
Next |
Pourriez vous m'aider? Un grand merci d'avance ;)