![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Show File in Window
I have the path to a file, say C:\path\to\file.txt. I need a way to open the folder where that file (file.txt) resides, and select it.
Since I am on a Windows machine, I can use the webbrowser module to load a path: import webbrowser webbrowser.open(r"C:\path\to\file.txt") Thanks in advance. I'm not even sure this is possible in Python. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Oh, err that sounds really strange. I couldn't see why there'd be support for something like that. If someone knows something in the win32api to prove me wrong, that'd be cool.
![]() Otherwise, I'd think it would call for something really obscure. Like synthesizing a keystroke using win32api.keybd_event. First off, have you ever used an application that does what you are trying to do? That might be a helpful clue as to if it is even possible. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
I'm not sure if it's the same in Windows, but on my Mac, when I download a file in my browser, I can go to the Download Manager window and click "Show File in Finder," and it will open a window with the file I just downloaded, selected. I'm trying to do something similar, although it's probably not going to be possible...
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
LaunchServices looks promising. Mac only, though.
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
That does sound pretty obscure. If i'm not mistaken the explorer uses a HTML rendering widget to display the folders and stuff? If you could find a way to get a reference to that rendering widget you could find a way to call some JavaScript in it and focus the folder. It'd be a pretty involved process though.
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
On the InternetExplorer you can click on File/Properties.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() |
Huh... Dietrich? What does that have to do with anything at all...?
![]() |
|
|
|
|
|
#8 |
|
Programmer
|
Perhaps you want to execute "explorer.exe /select, C:\path\to\file.txt" ?
Note the comma, as per MSKB. I dunno how to do it in python, but that should get you what you want. |
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
Oh wow! That's amazing, it works. :p So easy... so the code would then be...
import os
path = 'c:\\path\\file.txt'
os.system('explorer.exe /select, %s'%path)Edit: I'll post the code for if the path has spaces in it, when I get back from dinner. Post Edit: Oh! Nvm. It works with spaces already. :o Last edited by Sane; Jul 8th, 2006 at 6:49 PM. |
|
|
|
|
|
#10 |
|
Expert Programmer
|
Wow, thanks... I didn't think it was going to be possible! I'll try this out as soon as I get to work on Monday.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|