LoginSignup
1
1

More than 1 year has passed since last update.

PowerShellフォルダ選択ダイアログ

Posted at

前回PowerShellファイル選択ダイアログの記事を書いたが、ファイル選択ダイアログができればフォルダ選択もしたいというのが人情。

フォルダ選択ダイアログ.ps1
#名前空間指定
[void][System.Reflection.Assembly]::LoadWithPartialName("system.windows.forms")

#フォルダ参照ダイアログインスタンス生成
$dialog=New-Object System.Windows.Forms.FolderBrowserDialog

#ダイアログの説明表示
$dialog.Description="フォルダ選択"

#ダイアログ表示
$showdialog=$dialog.ShowDialog()

#選択したかどうか
if($showdialog -eq [System.Windows.Forms.DialogResult]::ok){
    
    #ここに動作内容記述
    #選択したパス表示
    Write-Host $dialog.SelectedPath

    #条件に当てはまるファイルに対して一括でファイル名を変更、Rename-Item -Path “名前を変更するファイルパス” -NewName “新しいファイル名”
    #ファイル名の拡張子変更
    #Get-ChildItem ($dialog.SelectedPath+"\*.jpg") | Rename-Item -NewName{$_.Name -Replace "\.jpg",".jpeg"}
    #ファイル名のファイル名変更
    Get-ChildItem ($dialog.SelectedPath+"\*.m4a") | Rename-Item -NewName{$_.Name -Replace "NG","OK"}

    <#
    #フォルダ内のファイル取得
    $filelist=Resolve-Path $dialog.SelectedPath

    #フォルダにループ
    foreach($foreachlist in $filelist){
    }
    #>
}
else{
    Write-Host "キャンセルしました。"
}

【参考文献】

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1