Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58825

Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder, desktop.BindToObject, desktop.GetDisplayNameOf

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; '21,': 0.07; 'advance': 0.07; 'def': 0.12; '0),': 0.16; 'dict': 0.16; 'exception:': 0.16; 'files:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'item)': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'pywin32': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:programming': 0.16; 'win7': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'programming': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'fine': 0.24; 'nearly': 0.26; 'header:In-Reply- To:1': 0.27; 'raise': 0.29; 'code': 0.31; '13,': 0.31; 'file:': 0.31; 'keys': 0.31; 'file': 0.32; 'there.': 0.32; 'running': 0.33; '(most': 0.33; 'skip:t 40': 0.33; 'subject:with': 0.35; 'skip:s 30': 0.35; 'received:84': 0.35; 'building': 0.35; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:- 60': 0.39; 'skip:p 20': 0.39; 'name': 0.63; 'different': 0.65; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; ',the': 0.84; 'dict.': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:skip:s 20': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=eKcq0hZ1 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=2LCq-pQfA8cA:10 a=y9hG98u0I74A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=gnl_eDp0SYMA:10 a=2L3WvmVdMwRWOAIorUYA:9 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Fri, 08 Nov 2013 17:51:52 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version 1.0
To python-list@python.org
Subject Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder, desktop.BindToObject, desktop.GetDisplayNameOf
References <1b6591af-904c-4a95-8a7b-ee0c63af75db@googlegroups.com>
In-Reply-To <1b6591af-904c-4a95-8a7b-ee0c63af75db@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2233.1383933110.18130.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383933110 news.xs4all.nl 15865 [2001:888:2000:d::a6]:52018
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58825

Show key headers only | View raw


On 08/11/2013 03:30, iMath wrote:
>
> When running the following code on WinXP , all is fine ,
> --------------------------------------------------------------
> from win32com.shell import shell
>
> def launch_file_explorer(path, files):
>
>      folder_pidl = shell.SHILCreateFromPath(path,0)[0]
>      desktop = shell.SHGetDesktopFolder()
>      shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder)
>      name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item) for item in shell_folder])
>      to_show = []
>      for file in files:
>          if file not in name_to_item_mapping:
>              raise Exception('File: "{}" not found in "{}"'.format(file, path))
>          to_show.append(name_to_item_mapping[file])
>      shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
> import os
>
>
> p=r'E:\aa'
> print(os.listdir(p))
> launch_file_explorer(p, os.listdir(p))
> --------------------------------------------------------------
>
> however ,when tested on Win7,I got the following error
>
> --------------------------------------------------------------
>
> ['b1', 'b2', 't.txt']
> Traceback (most recent call last):
>    File "D:\g.py", line 21, in <module>
>      launch_file_explorer(p, os.listdir(p))
>    File "D:\g.py", line 13, in launch_file_explorer
>      raise Exception('File: "{}" not found in "{}"'.format(file, path))
> Exception: File: "t.txt" not found in "E:\aa"
> --------------------------------------------------------------
> I nearly have no experience on pywin32 programming ,the above code is googled,anyone can help me fix this error ?thanks in advance !
>
It's building a dict where the key is the result of
desktop.GetDisplayNameOf(item, 0), and it's then not finding a given
name in that dict.

Try printing the keys to see what's there. It might be that
desktop.GetDisplayNameOf(item, 0) returns different strings in Win7
from those in WinXP.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

pywin32 programming error on Win7 with shell.SHGetDesktopFolder,desktop.BindToObject,desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-07 19:30 -0800
  Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,  desktop.BindToObject, desktop.GetDisplayNameOf Tim Golden <mail@timgolden.me.uk> - 2013-11-08 09:47 +0000
    Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,  desktop.BindToObject, desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-08 07:28 -0800
    Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,  desktop.BindToObject, desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-08 07:28 -0800
  Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,  desktop.BindToObject, desktop.GetDisplayNameOf MRAB <python@mrabarnett.plus.com> - 2013-11-08 17:51 +0000
    Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,  desktop.BindToObject, desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-09 21:23 -0800
  Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,desktop.BindToObject,desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-10 04:39 -0800
  Re: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,desktop.BindToObject,desktop.GetDisplayNameOf iMath <redstone-cold@163.com> - 2013-11-10 04:39 -0800

csiph-web