Question [RESOLU] Fermer tous les fichier ouverts

Plus d'informations
il y a 12 ans 11 mois #14581 par LAFFONT
Réponse de LAFFONT sur le sujet Re:Fermer tous les fichier ouverts
Bon, j'ai rajouté un morceau qui règle définitivement le problème de fichier cachés

[code:1]
foreach ($archive in $folderArchive){
$FichiersCaches = get-childitem \"$patharchiveFull\$archive\" -include '*s.db','.ds_*' -Force -Recurse
foreach ($FichierCache in $FichiersCaches){ Remove-Item $FichierCache -Force }
#on supprime les fichiers cachés pour ne pas le transférer et pouvoir supprimer les répertoires sans restrictions de droits
$resultPathArchive = Test-Path -Path \"$pathCibleFull\$archive\\"[/code:1]

Merci pour votre aide.
A+

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 1 mois #16971 par LAFFONT
Réponse de LAFFONT sur le sujet Re:Fermer tous les fichier ouverts
Une petite mise à jour

[code:1]
$drivearchive='D:'
$patharchive=$drivearchive + '\STUDIO';
$pathBackup = \"\\192.168.42.151\"
$cible = \"archives_studio\";
$templateDossier = \"_*_ARCHIVES\"
$logDir = \"logs\";

$diskbegin = Get-WmiObject Win32_LogicalDisk -Filter \"DeviceID='$drivearchive'\" | Select-Object Size,FreeSpace
$taillebegin = $diskbegin.freespace / (1024*1024*1024)
$taillebegin = [math]::round($taillebegin, 1)
$dateBegin = Get-Date -Format G

$resultCible = Test-Path -Path \"$pathBackup\$cible\"
if ($resultCible -ne $true){
Write-host -foregroundcolor 'green' \"Création de $pathBackup\$cible \" ;
New-Item -ItemType directory -Name \"$cible\" -Path \"$pathBackup\\"
}

$resultLog = Test-Path -Path \"$pathBackup\$cible\$logDir\"
if ($resultLog -ne $true){
Write-host -foregroundcolor 'green' \"Création de $pathBackup\$cible\$logDir \" ;
New-Item -ItemType directory -Name \"$logDir\" -Path \"$pathBackup\$cible\\"
}

$dt = get-date -format dd.MM.yyyy-HH.mm ((Get-Date).addDays(-1)) #recupération de la date d'hier pour créer un fichier horodaté
Move-Item \"$pathBackup\$cible\$logDir\Logs.log\" -Destination \"$pathBackup\$cible\$logDir\Log_$dt.log\"

$foldersources= @(Get-ChildItem -Path \"$patharchive\" | where {$_.PsIsContainer})
foreach ($sources in $foldersources){
$folderArchives= @(Get-ChildItem -Path \"$patharchive\$sources\\" -Name \"$templateDossier\"«»)
write-host \"Nombre de dossier d archive sous $patharchive\$sources\ : \" @($folderArchives).Count
if (@($folderArchives).Count -gt 0){ #On vérifie que nous avons trouvé des dossier $templateDossier
foreach ($archives in $folderArchives){
$patharchiveFull=\"$patharchive\$sources\$archives\"
$pathCibleFull=\"$pathBackup\$cible\$sources\$archives\"
$resultPathCibleFull=Test-Path -Path \"$pathCibleFull\"
if ($resultPathCibleFull -ne $true){ #On vérifie que la destination existe sinon on la crée
New-Item -ItemType directory -Name \"$archives\" -Path \"$pathBackup\$cible\$sources\"
}
$folderArchive=@(Get-ChildItem -Path \"$patharchiveFull\"«»)
$nbArchive = @($folderArchive).Count
\"Nombre de dossier à archiver dans $patharchiveFull : $nbArchive\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
if (@(Get-ChildItem -Path \"$patharchiveFull\" | where {$_.PsIsContainer}).Count -gt 0){ #On vérifie que les dossier $templateDossier trouvés ne soit pas vide.
foreach ($archive in $folderArchive){
$FichiersCaches = get-childitem \"$patharchiveFull\$archive\" -include '*s.db','.ds_*' -Force -Recurse
foreach ($FichierCache in $FichiersCaches){ Remove-Item $FichierCache -Force } #on supprime les fichiers cachés pour ne pas le transférer et pouvoir supprimer les répertoires sans restrictions de droits
$resultPathArchive = Test-Path -Path \"$pathCibleFull\$archive\\"
if ($resultPathArchive -ne $true){
Write-host -foregroundcolor 'green' \"Déplacement des dossier de $patharchiveFull\$archive vers $pathCibleFull\" ;
Copy-Item \"$patharchiveFull\$archive\" -Destination \"$pathCibleFull\" -Recurse -ErrorAction SilentlyContinue -ErrorVariable Copyerror
$Date = Get-Date -Format G
if ($?){
$Date + \" : Dossier(s) $patharchiveFull\$archive archivé(s) en $pathCibleFull\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
\" \" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
Get-ChildItem D:\PRODUCTION -Include \".DS_*\",\"*s.db\" -Force -Recurse |Remove-Item -Force
Remove-Item \"$patharchiveFull\$archive\" -Recurse -ErrorAction SilentlyContinue -ErrorVariable Removerror
if ($?){
$Date + \" : Dossier(s) $patharchiveFull\$archive supprimé(s).\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
\" \" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
}else{
\"Err - $Date - : La suppression de(s) dossier(s) $patharchiveFull\$archive a échouée(s).\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
\" \" + $Removerror| Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append

}
}else{
\"Err - $Date - : L'archivage dossier(s) $patharchiveFull\$archive a échoué.\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
\" \" + $Copyerror | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
}
}else{
Write-host -foregroundcolor 'red' \"Destination $pathCibleFull\$archive a déjà été archivé\"
\"Err - $Date - Destination $pathCibleFull\$archive a déjà été archivé\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
}
}
}
}
}else{
Write-host -foregroundcolor 'red' \"Aucune Archive à déplacer de $patharchive\$sources\\" ;
\"Bizz - Aucune Archive à déplacer de $patharchive\$sources\\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
}
}
$diskafter = Get-WmiObject Win32_LogicalDisk -Filter \"DeviceID='$drivearchive'\" | Select-Object Size,FreeSpace
$tailleafter = $diskafter.freespace / (1024*1024*1024)
$tailleafter = [math]::round($tailleafter, 1)
$dateAfter = Get-Date -Format G

\" - $dateBegin - : Espace disque avant l'opération : $taillebegin Go\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
\" - $dateAfter - : Espace disque après l'opération : $tailleafter Go\" | Out-File \"$pathBackup\$cible\$logDir\Logs.log\" -encoding utf8 -Append
Write-host -foregroundcolor 'green' \"Sauvegarde OK ! :«»)\";
[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.039 secondes
Propulsé par Kunena