Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Définition des en-têtes
- $Header = 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'
- #Choix du dernier Fichier File_F1 dans le dossier d'archives
- $SourcePath = ".\archives"
- $Filter = '*.txt'
- $Dernierearchive = Get-ChildItem -Path $SourcePath -File -Filter $Filter |
- Sort-Object LastWriteTime |
- Select-Object -Last 1
- $Dernierearchive
- # Import des fichiers
- $F1 = Import-Csv -Path ".\archives\$Dernierearchive" -Encoding Default -Header $Header -Delimiter ";"
- $F2 = Import-Csv -Path "GRH_TIL_F1.txt" -Encoding Default -Header $Header -Delimiter ";"
- $ListeAlias = Get-Content -Path ".\liste-fonction_comparaison\listealias.txt" -Encoding Default
- # Variable qui servira à stocker le résultat
- $result = @()
- # Récupère les différences d'ID (ajout, suppression)
- # Et stock dans $F1 et $F2 le statut SideIndicator pour les objects découverts, via le paramètre PassThru
- $result = (Compare-Object -ReferenceObject $F1 -DifferenceObject $F2 -Property A -PassThru) | Select-Object A, B, C, D, E, F, G, H, I, J, @{
- Label = "Code d'action"; Expression = {
- if ($_.SideIndicator -eq "=>") { 0 }
- else { 2 }
- }
- }
- # Récupère les modifications pour les doublons d'ID en comparant toutes les propriétés (A, B, C, D, E)
- $result += (Compare-Object -ReferenceObject @($F1 | Where-Object { $_.SideIndicator -eq $null }) -DifferenceObject @($F2 | Where-Object { $_.SideIndicator -eq $null }) -Property A, B, C, D, E, F, G, H, I, J -ErrorAction SilentlyContinue) | Where-Object { $_.SideIndicator -eq "=>" } | Select-Object A, B, C, D, E, F, G, H, I, J, @{ Label = "Code d'action"; Expression = { 1 } }
- # Identifie le travail métier et trie les résultats
- $result = $result | Select-Object *, @{
- Label = "IsAlias"; Expression = {
- if ($ListeAlias -contains $_.I) { $true }
- else { $false }
- }
- } | Sort-Object -Property "Code d'action" -Descending
- # Export
- $result | Where-Object { $_.IsAlias } | Select-Object A, B, C, D, E, F, G, H, I, J, "Code d'action" | Export-Csv -Path ".\import\File_F1_Import.csv" -NoTypeInformation -Encoding Default
- $result | Where-Object { !$_.IsAlias } | Select-Object A, B, C, D, E, F, G, H, I, J, "Code d'action" | Export-Csv -Path ".\erreur_import\File_F1_Import_Defaut.csv" -NoTypeInformation -Encoding Default
- #Archive F2
- Move-Item -Path "GRH_TIL_F1.txt" -Destination ".\archives\GRH_TIL_F1.txt"
- $SourceFilePath = ".\archives\GRH_TIL_F1.txt" #Chemin complet du fichier
- $DateNow = Get-Date -Format "ddMMyyyyhhmmss" #Date 20140924
- $FileName = [io.path]::GetFileNameWithoutExtension($SourceFilePath) #Récupère le nom du fichier uniquement
- $FileExtension = [io.path]::GetExtension($SourceFilePath) #Récupère l'extension du fichier uniquement
- Rename-Item -Path $SourceFilePath -newname "$FileName _ $DateNow$FileExtension" #Renommage du fichier
- # Create some var
- $Date = Get-Date -format "yyyy-MM-dd"
- $ArchiveName = "Archive-$date.zip"
- $ArchivePath = ".\archives\"
- $Source1Path = ".\archives\"
- # Identify the file in the SourcePath
- $Files = Get-ChildItem -Path $Source1Path -File -Filter ("*.txt") | Sort-Object LastWriteTime | Select-Object -First 1 # I'm use filter just in case of you have some other file in the folder
- # Now treatment
- foreach ($file in $Files)
- {
- Compress-Archive -Path $($file.fullName) -DestinationPath $ArchivePath\$ArchiveName -CompressionLevel Optimal -Update
- # this only copy the file in the archive and create the archive file if necessary
- # the -update parameter is necessary. At the first loop this create the archive file and add file in it, and at the others, this add file and not overwrite the archive file
- # Now it's time to delete the source file
- Remove-Item -Path $($file.fullName)
- }
- # #Création Sémaphore de fin de traitement
- $semaphore = new-item "E:\Interfaces_prototype\SEMAPHORES\fin_traitement_F1.ok" –type file -force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement