フォルダ選択のダイアログを開く
フォルダ選択するためのダイアログを開きたい。そこで選択したフォルダのパスを取得する。それらをどう行うか?
以下のコードのようにする。ボタンを押すとフォルダ選択ダイアログが開く。そこで選択されたフォルダパスは、dialog.SelectedPathで取得できる。
import System.Drawing import System.Windows.Forms from System.Drawing import * from System.Windows.Forms import * class MainForm(Form): def __init__(self): self.InitializeComponent() def InitializeComponent(self): self._button1 = System.Windows.Forms.Button() self.SuspendLayout() # # button1 # self._button1.Location = System.Drawing.Point(81, 94) self._button1.Name = "button1" self._button1.Size = System.Drawing.Size(113, 65) self._button1.TabIndex = 0 self._button1.Text = "Select Folder" self._button1.UseVisualStyleBackColor = True self._button1.Click += self.Button1Click # # MainForm # self.ClientSize = System.Drawing.Size(284, 262) self.Controls.Add(self._button1) self.Name = "MainForm" self.Text = "test" self.ResumeLayout(False) def Button1Click(self, sender, e): # ボタンを押したときの処理。フォルダ選択ダイアログを開く。 dialog = FolderBrowserDialog() dialog.ShowNewFolderButton = True dialog.SelectedPath = None if dialog.ShowDialog() == DialogResult.OK: print dialog.SelectedPath