iMath wrote: > When running the following code on WinXP , all is fine , > ... > 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 !
The issue here is not XP versus Win 7. The issue here is the Explorer folder settings. On your XP system, the user has selected the option to show the file extensions. On your Win 7 system, the user has NOT selected that option. You're using the GetDisplayNameOf API, which returns to you the file name exactly as it would be displayed in Explorer. When that option is off, the filename "t.txt" would be displayed as "t", so that's the key you are storing in name_to_item_mapping. The key "t.txt" is not found, as the error says. What you're doing here is a little bit dangerous, because "t.xls" and "t.txt" and "t.exe" will all return the same value from GetDisplayNameOf. You won't get a one-to-one assignment. Since you haven't explained what you actually expect this code to do, there's no way for us to make a suggestion on a better method. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc.
_______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32