Question
Besoin d'aide pour mon script
- Fontana
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 2
- Remerciements reçus 0
il y a 10 ans 3 mois #21147
par Fontana
Besoin d'aide pour mon script a été créé par Fontana
Bonjour,
Je suis actuellement en train d'apprendre le langage Powershell, j'ai de bonnes bases en Programmation Java si jamais.
Bref, je cherche de l'aide pour créer mon script qui consiste à choisir un répertoire ou un disque et d'y analyser le contenu pour ensuite afficher la taille des fichiers ainsi que leurs noms et les trier du plus grand au plus petit.
J'ai déjà fais l'interface de mon script ainsi que la fonction qui permet de trouver la taille du fichier et son nom et de les afficher.
Mon idée était la suivante pour trier mes fichiers par taille , elle consiste à créer un un tableau qui contiendrai la taille et le nom du fichier puis faire une boucle qui trie dans le bon ordre mes fichiers.
Je vous remercie déjà de votre aide.
Matthieu
Mon code:
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 25.09.2015 18:45
# Generated By: matth_000
########################################################################
#fonction qui permet de connaitre la taille de mon fichier en bit
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\") | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Drawing\") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$start = New-Object System.Windows.Forms.Button
$repchoix = New-Object System.Windows.Forms.Button
$affichage = New-Object System.Windows.Forms.RichTextBox
$label1 = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#
#Generated Event Script Blocks
#
#Provide Custom Code for events specified in PrimalForms.
$repchoix_OnClick={
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
[void]$FolderBrowser.ShowDialog()
$location = $FolderBrowser.SelectedPath
$affichage.Clear()
#TODO: Place custom script here
}
$start_OnClick= {
$files = Get-ChildItem -Recurse -Path $location -Force
function affichetaille {
param ([string]$chemin)
$i=0
gci $chemin -recurse -force| foreach -process {$i+=$_.length}
return $i}
Foreach ($file in $files) {
$nomfichier = [System.IO.Path]::GetFileNameWithoutExtension($file)
$affichage.AppendText(\"$nomfichier`t\")
$taille = affichetaille $file
$affichage.AppendText(\"$taille`n\")
}
}
#TODO: Place custom script here
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 406
$System_Drawing_Size.Width = 664
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = \"form1\"
$form1.Text = \"Primal Form\"
$start.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 125
$start.Location = $System_Drawing_Point
$start.Name = \"start\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 53
$System_Drawing_Size.Width = 136
$start.Size = $System_Drawing_Size
$start.TabIndex = 3
$start.Text = \"Lancer le space sniffer\"
$start.UseVisualStyleBackColor = $True
$start.add_Click($start_OnClick)
$form1.Controls.Add($start)
$repchoix.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 56
$repchoix.Location = $System_Drawing_Point
$repchoix.Name = \"repchoix\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 59
$System_Drawing_Size.Width = 138
$repchoix.Size = $System_Drawing_Size
$repchoix.TabIndex = 2
$repchoix.Text = \"Choisir un disque\"
$repchoix.UseVisualStyleBackColor = $True
$repchoix.add_Click($repchoix_OnClick)
$form1.Controls.Add($repchoix)
$affichage.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 219
$affichage.Location = $System_Drawing_Point
$affichage.Name = \"affichage\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 161
$System_Drawing_Size.Width = 608
$affichage.Size = $System_Drawing_Size
$affichage.TabIndex = 1
$affichage.Text = \"\"
$form1.Controls.Add($affichage)
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Font = New-Object System.Drawing.Font(\"Microsoft Sans Serif\",20,0,3,1)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 5
$System_Drawing_Point.Y = 5
$label1.Location = $System_Drawing_Point
$label1.Name = \"label1\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 48
$System_Drawing_Size.Width = 302
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 0
$label1.Text = \"PowerSpace Sniffer\"
$form1.Controls.Add($label1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
Je suis actuellement en train d'apprendre le langage Powershell, j'ai de bonnes bases en Programmation Java si jamais.
Bref, je cherche de l'aide pour créer mon script qui consiste à choisir un répertoire ou un disque et d'y analyser le contenu pour ensuite afficher la taille des fichiers ainsi que leurs noms et les trier du plus grand au plus petit.
J'ai déjà fais l'interface de mon script ainsi que la fonction qui permet de trouver la taille du fichier et son nom et de les afficher.
Mon idée était la suivante pour trier mes fichiers par taille , elle consiste à créer un un tableau qui contiendrai la taille et le nom du fichier puis faire une boucle qui trie dans le bon ordre mes fichiers.
Je vous remercie déjà de votre aide.
Matthieu
Mon code:
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
# Generated On: 25.09.2015 18:45
# Generated By: matth_000
########################################################################
#fonction qui permet de connaitre la taille de mon fichier en bit
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\") | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Drawing\") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$start = New-Object System.Windows.Forms.Button
$repchoix = New-Object System.Windows.Forms.Button
$affichage = New-Object System.Windows.Forms.RichTextBox
$label1 = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#
#Generated Event Script Blocks
#
#Provide Custom Code for events specified in PrimalForms.
$repchoix_OnClick={
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
[void]$FolderBrowser.ShowDialog()
$location = $FolderBrowser.SelectedPath
$affichage.Clear()
#TODO: Place custom script here
}
$start_OnClick= {
$files = Get-ChildItem -Recurse -Path $location -Force
function affichetaille {
param ([string]$chemin)
$i=0
gci $chemin -recurse -force| foreach -process {$i+=$_.length}
return $i}
Foreach ($file in $files) {
$nomfichier = [System.IO.Path]::GetFileNameWithoutExtension($file)
$affichage.AppendText(\"$nomfichier`t\")
$taille = affichetaille $file
$affichage.AppendText(\"$taille`n\")
}
}
#TODO: Place custom script here
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 406
$System_Drawing_Size.Width = 664
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = \"form1\"
$form1.Text = \"Primal Form\"
$start.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 17
$System_Drawing_Point.Y = 125
$start.Location = $System_Drawing_Point
$start.Name = \"start\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 53
$System_Drawing_Size.Width = 136
$start.Size = $System_Drawing_Size
$start.TabIndex = 3
$start.Text = \"Lancer le space sniffer\"
$start.UseVisualStyleBackColor = $True
$start.add_Click($start_OnClick)
$form1.Controls.Add($start)
$repchoix.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 16
$System_Drawing_Point.Y = 56
$repchoix.Location = $System_Drawing_Point
$repchoix.Name = \"repchoix\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 59
$System_Drawing_Size.Width = 138
$repchoix.Size = $System_Drawing_Size
$repchoix.TabIndex = 2
$repchoix.Text = \"Choisir un disque\"
$repchoix.UseVisualStyleBackColor = $True
$repchoix.add_Click($repchoix_OnClick)
$form1.Controls.Add($repchoix)
$affichage.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 219
$affichage.Location = $System_Drawing_Point
$affichage.Name = \"affichage\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 161
$System_Drawing_Size.Width = 608
$affichage.Size = $System_Drawing_Size
$affichage.TabIndex = 1
$affichage.Text = \"\"
$form1.Controls.Add($affichage)
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$label1.Font = New-Object System.Drawing.Font(\"Microsoft Sans Serif\",20,0,3,1)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 5
$System_Drawing_Point.Y = 5
$label1.Location = $System_Drawing_Point
$label1.Name = \"label1\"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 48
$System_Drawing_Size.Width = 302
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 0
$label1.Text = \"PowerSpace Sniffer\"
$form1.Controls.Add($label1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm
Connexion ou Créer un compte pour participer à la conversation.
- Philippe
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 1778
- Remerciements reçus 21
il y a 10 ans 3 mois #21157
par Philippe
Réponse de Philippe sur le sujet Re:Besoin d'aide pour mon script
Bonjour BlackSnoww
BlackSnoww écrit:
peut tu aussi nous aider en mettant les balises code sur les parties scripts, stp. Ca nous facilite le travail de lecture de ton code !
pour ça tu surligne ton code et tu clique sur le bouton code au dessus de la zone de saisi du texte
->tu as la possibilité d’éditer (modifier) ton premier post
merci
BlackSnoww écrit:
Je vous remercie déjà de votre aide.
peut tu aussi nous aider en mettant les balises code sur les parties scripts, stp. Ca nous facilite le travail de lecture de ton code !
pour ça tu surligne ton code et tu clique sur le bouton code au dessus de la zone de saisi du texte
->tu as la possibilité d’éditer (modifier) ton premier post
merci
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.037 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Besoin d'aide pour mon script