Question Inputbox pour trouver un chemin

Plus d'informations
il y a 1 an 11 mois #32210 par Cédric
Bonjour à tous,

Je cherche le moyen pour insérer en glissant un fichier ou dossier dans une inputbox et qui me donnerait le chemin complet du dossier ou fichier.

 Inputbox
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$msk=[Microsoft.VisualBasic.Interaction]::InputBox("Entrer le fichier : ")
$msk

la même chose que le "read-host" mais en fenêtre en gros.





 

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

Plus d'informations
il y a 1 an 11 mois #32213 par Cédric
Réponse de Cédric sur le sujet Inputbox pour trouver un chemin
j'ai mis le doigt sur ce code ;

# PowerShell Drag & Drop sample
# Usage:
# powershell -sta -file dragdrop.ps1
# (-sta flag is required)
#
Function DragDropSample() {
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.text = "Lien"
$listBox = New-Object Windows.Forms.ListBox
$listBox.Dock = [System.Windows.Forms.DockStyle]::Fill
$handler = {
if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
$listBox.Items.Add($filename)
}
}
}
$form.AllowDrop = $true
$form.Add_DragEnter($handler)
$form.Controls.Add($listBox)
$form.ShowDialog()

}

DragDropSample | Out-Null


mais je ne comprends pas comment extraire le chemin.

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

Plus d'informations
il y a 1 an 11 mois #32222 par Philippe
Réponse de Philippe sur le sujet Inputbox pour trouver un chemin
Salut Cédric

déja une petite formation express sur les forms  et une autre pour une explication differente 

voici une version qui fonctionne :
Function DragDropSample() {
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
    $form = New-Object Windows.Forms.Form
    $form.text = "Lien"
    $listBox = New-Object Windows.Forms.ListBox
    $listBox.Dock = [System.Windows.Forms.DockStyle]::Fill
    $handler = {
        if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
            foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
                $listBox.Items.Add($filename)
                }
            }
        }
    $form.AllowDrop = $true
    $form.Add_DragEnter($handler)
    $form.Controls.Add($listBox)


    $result = $form.ShowDialog()
    $listBox.Items
    }

$chemin = DragDropSample 
$chemin
$chemin contien .... le nom du fichier avec le chemin complet !

je pense qu'il serait sympas d'avoir un bouton pour sortir, tu trouve pas ?

il a fallu changer quelques partie, principalement la listbox, que j'ai transformé en textbox plus petite 
 
Function DragDropSample() {
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

    $Form = New-Object System.Windows.Forms.Form
    [System.Windows.Forms.Application]::EnableVisualStyles()

    $Form.ClientSize = ‘400,100’
    $Form.Text = "Lien"


    $Bouton = New-Object System.Windows.Forms.Button
    $Bouton.Location = New-Object System.Drawing.Point(30,50)
    $Bouton.Width = 80
    $Bouton.Height = 40
    $Bouton.Text = "Quitter"
    $Bouton.Add_Click(
        {
        $form.Close();
        })
    $form.Controls.Add($Bouton)

    $TextBox = New-Object System.Windows.Forms.TextBox
    $TextBox.Location = New-Object System.Drawing.Point(30,110)
    $TextBox.Width = 200

    $TextBox.Dock = [System.Windows.Forms.DockStyle]::Fill
    $handler = {
        if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
            foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
                $TextBox.text = $filename
                }
            }
        }
    $TextBox.AllowDrop = $true
    $TextBox.Add_DragEnter($handler)

    $Form.controls.Add($TextBox)

    $result = $Form.ShowDialog()

    $TextBox.text

    }

$chemin = DragDropSample 
$chemin

à toi de personnaliser :).

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

Plus d'informations
il y a 1 an 11 mois #32223 par Cédric
Réponse de Cédric sur le sujet Inputbox pour trouver un chemin
Salut Philippe,

Merci beaucoup pour les liens et pour ton aide précieuse.
je viens de tester et c'est tip top ce qui me fallait et avec le bouton c'est vraiment super.
Je plancherais sur ce script afin de mieux le comprendre. merci encore

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

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