Welcome, guest | Sign In | My Account | Store | Cart

This recipie will run two copies of Windows Explorer, resize them to fit each of them to half the desktop size and place them side by side to facilitate file management between two directories or disk drives.

Python, 35 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from win32gui import EnumWindows, SetWindowPos, GetDesktopWindow, \
     GetWindowRect, FindWindow, GetClassName, ShowWindow
import os, time
import pywintypes

def enumWinProc(h, lparams):
    
    if GetClassName(h) == 'ExploreWClass':
        lparams.append(h)

winList = []
EnumWindows(enumWinProc,winList)
winCnt = len(winList)
if winCnt == 0: # No Explorer running
    os.system('explorer.exe')
    while 1:
        try:
            FindWindow('ExploreWClass',None) #Wait for first instance to run
        except pywintypes.error,e:
            pass
        else:
            break
        time.sleep(0.1) # Sleep for a while before continuing
    os.system('explorer.exe') # Start second instance
elif winCnt == 1:
    os.system('explorer.exe') # Start second instance
time.sleep(2) # Wait for Explorer to run
winList = []
EnumWindows(enumWinProc,winList) # Get handles of running Explorer
hDesk = GetDesktopWindow()
(dLeft,dTop,dRight,dBottom) = GetWindowRect(hDesk) # Get desktop size
SetWindowPos(winList[0],0,dRight/2,0,dRight/2,dBottom,0) # Set the windows sizes
SetWindowPos(winList[1],0,0,0,dRight/2,dBottom,0)
ShowWindow(winList[0],1) #Show the windows
ShowWindow(winList[1],1)
    

File management using the Windows Explorer can be quite convenient via the drag-and-drop method between two directories or disk drives. However, starting two copies of Windows Explorer do not always place the Explorer windows in convenient positions to facilitate drag-and-drop. The Explorer windows can end up in arbitrary positions anywhere on the desktop, and may overlap each other which will make drag-and-drop tedious. This script will run two copies of Windows Explorer side-by-side to facilitate files/directories dragging and dropping.

This script will need the Win32 Extension for Python, which is also packaged in the ActivePython distribution. One of the known issue is that some older versions of Win32 Extension, e.g. that for Python 2.2, may not contain all the functions required from the win32gui.

2 comments

xixi haha 18 years, 6 months ago  # | flag

Good stuff. I am using it. It's quite handy.

A bug is that it doesn't count the size of the taskbar. So the status bar of the explorers aren't visible. (I am using Win Xp)

John Menzies 12 years, 11 months ago  # | flag

On my Windows 7, I needed to change the GetClassName to 'CabinetWClass' from 'ExploreWClass' Needed changing in two places. Now it works correctly.