Question
[Résolu]probleme d'affichage
- Axel
- Auteur du sujet
- Hors Ligne
- Membre elite
-
Réduire
Plus d'informations
- Messages : 176
- Remerciements reçus 0
il y a 10 ans 11 mois #19917
par Axel
[Résolu]probleme d'affichage a été créé par Axel
bonjour,
mon code permet d'identifier les doublons, alors il procède par 3 étapes , 1) il demande si vous voulez les afficher , 2) il demande si vous voulez afficher leur md5 et 3) si vous voulez exporter les données sur votre ordinateur.
1 ) il m'affiche fullname et la taille du fichier
2 ) il m'affiche fullname et md5
3 ) il extrait fullname et md5
comment, à l'étape 2 afficher fullname md5 et la taille du fichier ?
comment extraire ces 3 infos ?
[code:1]#conversion KiloOctet
$taille = 10kb
#recherche des fichiers par rapport à la taille
$files = gci * -recurse -force |
where-object {$_.length -gt $taille}
#création
$doublons = $files |
sort-object length |
group-object length |
where-object {$_.count -gt 1}
function Clear-KeyboardBuffer {
while ($Host.UI.RawUI.KeyAvailable)
{ $null = $Host.UI.RawUI.ReadKey(\"NoEcho,IncludeKeyDown,IncludeKeyUp\"«»)}
}
function YesNo {
param(
$Caption,
$Message,
[ValidateSet(\"Yes\",\"No\"«»)]
$DefaultChoice=\"No\"
)
Clear-KeyboardBuffer
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription \"&Yes\"
$No = New-Object System.Management.Automation.Host.ChoiceDescription \"&No\"
$Choices = [System.Management.Automation.Host.ChoiceDescription[]]($Yes,$No)
$Host.UI.PromptForChoice($Caption,$Message,$Choices,([byte]($DefaultChoice -eq \"no\"«»)))
}
function Get-FileHash {
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$true, ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$True)]
[Alias(\"PSPath\",\"FullName\"«»)]
[string[]]$Path,
[Parameter(Position=1)]
[ValidateSet(\"MD5\"«»)]
[string[]]$Algorithm = \"MD5\"
)
Process {
ForEach ($item in $Path) {
$item = (Resolve-Path $item).ProviderPath
If (-Not ([uri]$item).IsAbsoluteUri) {
Write-Verbose (\"{0} is not a full path, using current directory: {1}\" -f $item,$pwd)
$item = (Join-Path $pwd ($item -replace \"\.\\\",\"\"«»))
}
If(Test-Path $item -Type Container) {
Write-Warning (\"Cannot calculate hash for directory: {0}\" -f $item)
Return
}
$object = New-Object PSObject -Property @{
Path = $item
}
#Ouverture \"stream\"
$stream = ([IO.StreamReader]$item).BaseStream
foreach ($Type in $Algorithm) {
[string]$hash = -join ([Security.Cryptography.HashAlgorithm]::Create( $Type ).ComputeHash( $stream ) |
ForEach {\"{0:«»x0}\" -f $_ })
$null = $stream.Seek(0,0)
$object = Add-Member -InputObject $Object -MemberType NoteProperty -Name $Type -Value $Hash -PassThru
}
$object.pstypenames.insert(0,'System.IO.FileInfo.Hash')
#Sortie du Hash et du chemin
Write-Output $object
#Fermeture \"stream\"
$stream.Close()
}
}
}
function new-rapport {
param($fichier)
#construit un nouvel objet à partir d'un objet fichier
#par défaut le résultat est émis dans le pipeline
select-object -inputobject $fichier -property 'FullName','Length'
}
#affichage
#boucle sur la collection principale
$rapport = $doublons |
foreach-object {
#boucle sur la collection group de chaque doublon
$_.group |
foreach-object {
#boucle sur la collection de fichiers de chaque group
new-rapport -fichier $_
}#file
}#group
$i = 0
#calcul le nombre de fichiers trouvé
$rapport | foreach {
$i = $i + 1
}
$Yes = 0
$No = 1
$Choice = $No
if ($i -gt 1)
{
$Choice = YesNo -message \"`n$i fichier(s) trouvé(s), voulez-vous les afficher ?\"
}
else
{
write-host \"`nIl n'y a pas de doublon`n\"
}
if ($Choice -eq $Yes)
{
$rapport | format-table
$Choice = YesNo -message \"`nVoulez-vous afficher leur MD5 ?\"
if ($Choice -eq $Yes)
{
$rapport | Get-FileHash
$Choice = YesNo -message \"`nVoulez-vous exporter les informations ?\"
if ($Choice -eq $Yes)
{
$rapport | Get-FileHash | export-csv C:\Temp\RapportFiles.csv
write-host \"Les informations sont localisés dans C:\Temp\RapportFiles.csv\"
}
}
}[/code:1]<br><br>Message édité par: Harcide, à: 9/06/15 09:15
mon code permet d'identifier les doublons, alors il procède par 3 étapes , 1) il demande si vous voulez les afficher , 2) il demande si vous voulez afficher leur md5 et 3) si vous voulez exporter les données sur votre ordinateur.
1 ) il m'affiche fullname et la taille du fichier
2 ) il m'affiche fullname et md5
3 ) il extrait fullname et md5
comment, à l'étape 2 afficher fullname md5 et la taille du fichier ?
comment extraire ces 3 infos ?
[code:1]#conversion KiloOctet
$taille = 10kb
#recherche des fichiers par rapport à la taille
$files = gci * -recurse -force |
where-object {$_.length -gt $taille}
#création
$doublons = $files |
sort-object length |
group-object length |
where-object {$_.count -gt 1}
function Clear-KeyboardBuffer {
while ($Host.UI.RawUI.KeyAvailable)
{ $null = $Host.UI.RawUI.ReadKey(\"NoEcho,IncludeKeyDown,IncludeKeyUp\"«»)}
}
function YesNo {
param(
$Caption,
$Message,
[ValidateSet(\"Yes\",\"No\"«»)]
$DefaultChoice=\"No\"
)
Clear-KeyboardBuffer
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription \"&Yes\"
$No = New-Object System.Management.Automation.Host.ChoiceDescription \"&No\"
$Choices = [System.Management.Automation.Host.ChoiceDescription[]]($Yes,$No)
$Host.UI.PromptForChoice($Caption,$Message,$Choices,([byte]($DefaultChoice -eq \"no\"«»)))
}
function Get-FileHash {
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$true, ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$True)]
[Alias(\"PSPath\",\"FullName\"«»)]
[string[]]$Path,
[Parameter(Position=1)]
[ValidateSet(\"MD5\"«»)]
[string[]]$Algorithm = \"MD5\"
)
Process {
ForEach ($item in $Path) {
$item = (Resolve-Path $item).ProviderPath
If (-Not ([uri]$item).IsAbsoluteUri) {
Write-Verbose (\"{0} is not a full path, using current directory: {1}\" -f $item,$pwd)
$item = (Join-Path $pwd ($item -replace \"\.\\\",\"\"«»))
}
If(Test-Path $item -Type Container) {
Write-Warning (\"Cannot calculate hash for directory: {0}\" -f $item)
Return
}
$object = New-Object PSObject -Property @{
Path = $item
}
#Ouverture \"stream\"
$stream = ([IO.StreamReader]$item).BaseStream
foreach ($Type in $Algorithm) {
[string]$hash = -join ([Security.Cryptography.HashAlgorithm]::Create( $Type ).ComputeHash( $stream ) |
ForEach {\"{0:«»x0}\" -f $_ })
$null = $stream.Seek(0,0)
$object = Add-Member -InputObject $Object -MemberType NoteProperty -Name $Type -Value $Hash -PassThru
}
$object.pstypenames.insert(0,'System.IO.FileInfo.Hash')
#Sortie du Hash et du chemin
Write-Output $object
#Fermeture \"stream\"
$stream.Close()
}
}
}
function new-rapport {
param($fichier)
#construit un nouvel objet à partir d'un objet fichier
#par défaut le résultat est émis dans le pipeline
select-object -inputobject $fichier -property 'FullName','Length'
}
#affichage
#boucle sur la collection principale
$rapport = $doublons |
foreach-object {
#boucle sur la collection group de chaque doublon
$_.group |
foreach-object {
#boucle sur la collection de fichiers de chaque group
new-rapport -fichier $_
}#file
}#group
$i = 0
#calcul le nombre de fichiers trouvé
$rapport | foreach {
$i = $i + 1
}
$Yes = 0
$No = 1
$Choice = $No
if ($i -gt 1)
{
$Choice = YesNo -message \"`n$i fichier(s) trouvé(s), voulez-vous les afficher ?\"
}
else
{
write-host \"`nIl n'y a pas de doublon`n\"
}
if ($Choice -eq $Yes)
{
$rapport | format-table
$Choice = YesNo -message \"`nVoulez-vous afficher leur MD5 ?\"
if ($Choice -eq $Yes)
{
$rapport | Get-FileHash
$Choice = YesNo -message \"`nVoulez-vous exporter les informations ?\"
if ($Choice -eq $Yes)
{
$rapport | Get-FileHash | export-csv C:\Temp\RapportFiles.csv
write-host \"Les informations sont localisés dans C:\Temp\RapportFiles.csv\"
}
}
}[/code:1]<br><br>Message édité par: Harcide, à: 9/06/15 09:15
Connexion ou Créer un compte pour participer à la conversation.
- Axel
- Auteur du sujet
- Hors Ligne
- Membre elite
-
Réduire
Plus d'informations
- Messages : 176
- Remerciements reçus 0
il y a 10 ans 11 mois #19938
par Axel
Réponse de Axel sur le sujet Re:probleme d'affichage
up !
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.032 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- [Résolu]probleme d'affichage