Board logo

标题: [转载代码] [PowerShell每日技巧]创建一个文件夹选择器(20131209) [打印本页]

作者: DAIC    时间: 2013-12-20 17:16     标题: [PowerShell每日技巧]创建一个文件夹选择器(20131209)

To add a little glamour to your scripts, here are a few lines of code that display a folder selector dialog. When a user selects a folder, your script receives the selection and can work with the selected path:
  1. Add-Type -AssemblyName System.Windows.Forms
  2. [System.Windows.Forms.Application]::EnableVisualStyles()
  3. $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
  4. $null = $FolderBrowser.ShowDialog()
  5. $Path = $FolderBrowser.SelectedPath
  6. "You selected: $Path"
复制代码
Note the first two lines: they are not necessary when you run the code inside the ISE editor, but you do need them inside the powershell.exe. So keep these lines to make sure your code runs in all PowerShell hosts.

http://powershell.com/cs/blogs/tips/archive/2013/12/09/create-a-folder-selector.aspx




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2