Open Folder in Desktop

K

Kamilche

Is there a command you can execute in Python that will open a window on
the desktop, such as 'My Documents'? Kind of like 'system', but for
folder names, not just programs. I'm running on Windows 2000.
 
?

=?ISO-8859-1?Q?Ulf_G=F6ransson?=

Kamilche said:
Is there a command you can execute in Python that will open a window on
the desktop, such as 'My Documents'? Kind of like 'system', but for
folder names, not just programs. I'm running on Windows 2000.

Maybe this is good enough?

os.system("explorer " + folder_path)

/ug
 
D

Dennis Benzinger

Kamilche said:
Is there a command you can execute in Python that will open a window on
the desktop, such as 'My Documents'? Kind of like 'system', but for
folder names, not just programs. I'm running on Windows 2000.

Here are some commands you can use (tested on WinXP, so YMMV):


1. The os.system function

import os
os.system('explorer "c:\program files"')

This has the disadvantage that a cmd.exe windows is also opened,
because os.system executes the command in a subshell.

But using this approach the explorer starts in front of all other windows.


2. The os.startfile function

import os
os.startfile("C:\program files")

Using startfile doesn't open a cmd.exe window, but the folder window
is not started in front of the other windows


3. The subprocess.Popen function

import subprocess
subprocess.Popen('explorer "C:\program files"')

With subprocess.Popen no cmd.exe window is opened and the explorer
starts in front of the other windows.
But the subprocess module is new in Python 2.4.



Bye,
Dennis
 
S

Steve Holden

Kamilche said:
Is there a command you can execute in Python that will open a window on
the desktop, such as 'My Documents'? Kind of like 'system', but for
folder names, not just programs. I'm running on Windows 2000.
os.system("start .")

works for me.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,218
Messages
2,571,124
Members
47,725
Latest member
Rudy

Latest Threads

Top