# ******************************************************************************
# NOM DU PROGRAMME : l_journalier.ps1
# AUTEUR : Moi
# Mes coordonnées
# DATE DE LA VERSION : 16/09/2015
# DESCRIPTION : Analyse des repertoires contenant les FM
# pour mise a disposition des erreurs et des mises a jour
# ******************************************************************************
$basepath = "m:\AFFAIRES_N4FM"
$cumulfmdatafile = "m:\SCRIPT\data\fm_cumul.csv"
$cumulfmdatafilep = "m:\SCRIPT\data\fm_cumul_p.csv"
. .\programs\_commun.ps1
$nompgm = "l_journalier.ps1"
$auteurpgm = "Moi"
$datepgm = "16/09/2015"
$descriptionpgm = "Analyse des repertoires contenant les FM"
fonc-titre $nompgm $auteurpgm $datepgm $descriptionpgm
$fichiers = @()
$affaires = Get-ChildItem $basepath | sort-object name | where {$_.name -notlike "_*" -and $_.attributes -eq "Directory"} | Select-Object name
if (Test-Path $cumulfmdatafile)
{
$flag_existant = 1
$fichiers_actuels = Import-Csv $cumulfmdatafile
$maxrang_brut = $fichiers_actuels | Measure-Object rang -Maximum
$maxrang = $maxrang_brut.Maximum
}
else
{
$flag_existant = 0
}
foreach ($affaire in $affaires)
{
$chemin_affaire = $basepath+"\"+$affaire.Name
$affaire_1 = $chemin_affaire
$affaire_1_length = $affaire_1.Length
Write-Host "$chemin_affaire"
foreach ($lot in $chemin_affaire)
{
$se = Get-ChildItem $lot
foreach ($objet in $se)
{
$chemin = $chemin_affaire+"\"+$objet.name+"\FM"
if (Test-Path $chemin)
{
$fichiers_brut = Get-ChildItem $chemin | where {$_.attributes -ne "Directory"}
foreach ($ligne in $fichiers_brut)
{
$tab_exploit_chemin = $chemin.Split("\")
$nomfichier = $ligne.basename
$extension = $ligne.extension
$ticks = $ligne.lastwritetime.Ticks
$repertoire = $chemin.Substring((($affaire_1_length))+1,($chemin.Length) - $affaire_1_length - 1)
$x = New-Object psobject
$x | Add-Member -Name "statut_document" -MemberType NoteProperty -Value "Erreur"
$x | Add-Member -Name "rang" -MemberType NoteProperty -Value "0"
$x | Add-Member -Name "action" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "currentdate" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "lancement" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "id" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "lot" -MemberType NoteProperty -Value $tab_exploit_chemin[2]
$x | Add-Member -Name "lastwrt" -MemberType NoteProperty -Value $ticks
$x | Add-Member -Name "filedate" -MemberType NoteProperty -Value (fonc-ticks-to-human-readable $ticks)
$x | Add-Member -Name "repertoire" -MemberType NoteProperty -Value $repertoire
$x | Add-Member -Name "fullfilename" -MemberType NoteProperty -Value $ligne.fullname
$x | Add-Member -Name "extension" -MemberType NoteProperty -Value $extension
$x | Add-Member -Name "taille" -MemberType NoteProperty -Value $ligne.length
$x | Add-Member -Name "fullpath" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "shortname" -MemberType NoteProperty -Value $nomfichier
$x | Add-Member -Name "docname" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "fm" -MemberType NoteProperty -Value ""
$x | Add-Member -Name "se" -MemberType NoteProperty -Value $tab_exploit_chemin[3]
$fichiers += $x
}
}
}
}
}
if ($flag_existant -eq 0)
{
$increment = 0
foreach ($ligne in $fichiers)
{
$increment ++
$ligne.action = "AJOUTE"
$ligne.rang = $increment
}
}
else
{
echo "Le fichier $cumulfmdatafile existe"
foreach ($ligne_actuel in $fichiers_actuels)
{
# $ligne_actuel.fullfilename
if ($fichiers | select * | where {$_.fullfilename -eq $ligne_actuel.fullfilename})
{
echo "vrai "
}
else
{
echo "faux"
}
}
echo "------------------------------------"
foreach ($ligne in $fichiers)
{
# $ligne_actuel.fullfilename
Update-List -Replace $_.statut_document -Property
if ($fichiers_actuel | select * | where {$_.fullfilename -eq $ligne.fullfilename})
{
echo "vrai "
}
else
{
echo "faux"
}
}
}
sleep 100
foreach ($ligne in $fichiers)
{
$cas = $ligne.shortname.substring(0,2)
switch ($cas)
{
FM
{
$x = $ligne.shortname
echo "ceci est une FM $x"
if ($ligne.shortname -match 'FM.......P(B|C|CV|CZ)\s')
{
echo "FM conforme"
}
}
CC
{
$x = $ligne.shortname
echo "ceci est une CC $x"
}
AN
{
$x = $ligne.shortname
echo "ceci est une ANC $x"
}
CF
{
$x = $ligne.shortname
echo "ceci est une CFA $x"
}
}
}
$fichiers | Export-Csv $cumulfmdatafile -Encoding Unicode -NoTypeInformation
fonc-convert-csv $cumulfmdatafile $cumulfmdatafilep
# Clear-Host
Write-Host "Fin du traitement"
Write-Host "."
# fonc-pause
. $cumulfmdatafilep # ==> Pour débogage
Partager