Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 7th, 2006, 7:39 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 931
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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")
However, this does not select the file. (I do not want to open it, just to select it.)

Thanks in advance. I'm not even sure this is possible in Python.
titaniumdecoy is offline   Reply With Quote
Old Jul 7th, 2006, 7:50 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,094
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is online now   Reply With Quote
Old Jul 7th, 2006, 8:11 PM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 931
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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...
titaniumdecoy is offline   Reply With Quote
Old Jul 8th, 2006, 7:36 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
LaunchServices looks promising. Mac only, though.
Arevos is offline   Reply With Quote
Old Jul 8th, 2006, 10:44 AM   #5
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
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.
Cerulean is offline   Reply With Quote
Old Jul 8th, 2006, 3:07 PM   #6
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
On the InternetExplorer you can click on File/Properties.
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Jul 8th, 2006, 3:43 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,094
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Huh... Dietrich? What does that have to do with anything at all...?
Sane is online now   Reply With Quote
Old Jul 8th, 2006, 6:14 PM   #8
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
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.
niteice is offline   Reply With Quote
Old Jul 8th, 2006, 6:22 PM   #9
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,094
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is online now   Reply With Quote
Old Jul 8th, 2006, 8:52 PM   #10
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 931
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC