Shell.BrowseForFolder in Python, how to retrieve folder path
<p>I have the following code which displays the Windows folder selection window:</p>

<pre><code>from comtypes.client import CreateObject
shell = CreateObject("Shell.Application")
folder = shell.BrowseForFolder(0, "Select a folder", 1)
</code></pre>

<p>The Microsoft doc doesn't say anything about how to retrieve (the selected) folder path, anyway, a solution exists on the net for VB (for example <a href="http://stackoverflow.com/questions/31904226/shell-application-browseforfolder-how-do-i-get-full-path-of-folder-object">here</a>):</p>

<pre><code>path = folder.Self.Path
</code></pre>

<p>This solution do not translate to comtypes, and a <code>help(folder)</code> do not show any <code>Self</code> property, it seems that <code>BrowseForFolder</code> returns a <code>FOLDER</code> type, but <code>Self</code> is a property of <code>FOLDER2</code> type, any one know why?</p>

<p>As said TessellatingHeckler above, it works with win32com:</p>

<pre><code>import win32com.client

shell = win32com.client.Dispatch("Shell.Application")
folder = shell.BrowseForFolder(0, "Now browse...", 1)
print(folder.Self.Path)
</code></pre>

<p>But if you really want to use comtypes, here is a workaround:</p>

<pre><code>from comtypes.client import CreateObject

shell = CreateObject("Shell.Application")
folder = shell.BrowseForFolder(0, "Now browse...", 1)
name = folder.Title
for item in folder.ParentFolder.Items():
    if item.Name == name:
        print(item.Path)
</code></pre>

python activex comtypes