Setting Current Dir in Python

  • Thread starter Sandipan Gangopadhyay
  • Start date
S

Sandipan Gangopadhyay

Hi all!

I have utility programs in Python that do clean up, image processing tasks
on files in a folder. I just drop the program into the folder and run it.

I have been double clicking on a Python program in my Windows XP Home to
make it run . it sets the program's directory as the current directory when
it runs.

I have recently installed Python 2.5.1 and Pythonwin (without any errors) on
Windows Vista Ultimate.

Now, the programs run fine within Pythonwin IDE when current directory is
set to the program's directory.

But, when I double click them from Windows Explorer, the program is not run.

If I run the following program:

============================================================================
===============
# MODULE IMPORT
try:
import time, os, Image, urllib, string, math, os.path, filecmp, shutil,
sys
except:
strInput = raw_input("Failed import. Hit enter key to continue.")
pass

# FIGURE OUT CURR DIR
try:
print "CURENT = %s" % os.listdir(".")
print "PARENT = %s" % os.listdir("..")
print "ABS PATH = %s" % os.path.abspath(".")
print "CURENT = %s" % os.listdir(os.curdir)
print "PARENT = %s" % os.listdir(os.pardir)
except:
strInput = raw_input("Failed os module calls. Hit enter key to end.")
pass

print
strInput = raw_input("Hit enter key to end program")

Through Pythonwin IDE without setting the directory (using Open, or Save
As), I get:

============================================================================
===============
CURENT = ['addins', 'AppPatch', 'assembly', 'atl80.dll', . - snip - . ,
'winsxs', 'WMSysPr9.prx', 'xpsp1hfm.log', '_default.pif']
PARENT = ['$Recycle.Bin', 'autoexec.bat', 'Boot', 'bootmgr', 'BOOTSECT.BAK',
'config.sys', 'Documents and Settings', . - snip - . , 'Program Files',
'ProgramData', 'Python25', . - snip - . , 'System Volume Information',
'temp', 'Users', 'Windows']
ABS PATH = C:\Windows
CURENT = ['addins', 'AppPatch', 'assembly', 'atl80.dll', . - snip - ., ,
'winsxs', 'WMSysPr9.prx', 'xpsp1hfm.log', '_default.pif']
PARENT = ['$Recycle.Bin', 'autoexec.bat', 'Boot', 'bootmgr', 'BOOTSECT.BAK',
'config.sys', 'Documents and Settings', . - snip - . , 'Program Files',
'ProgramData', 'Python25', . - snip - . , 'System Volume Information',
'temp', 'Users', 'Windows']

If I run it using double click on the program through Windows Explorer, I
get:

============================================================================
===============
Nothing . the window closes immediately. Despite the except catches.

If I run it from a Command Prompt, by first navigating to the program's
directory and then specifying [ python.exe SandhirFileMonitor.py ], I get:

============================================================================
===============
sys:1: DeprecationWarning: Non-ASCII character '\xef' in file
SandhirFileMonitor.py on line 356, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details
Failed import. Hit enter key to continue.
CURENT = ['Diff.txt', 'Folder2', 'report-templates', 'reports - Copy
(2).html','reports - Copy (3).html', 'reports - Copy (4).html', 'reports -
Copy (5).html', 'reports - Copy.html', 'reports.html',
'SandhirFileBackupUtility - Copy.py', 'SandhirFileBackupUtility.py',
SandhirFileBackupUtility.py - Shortcut.lnk', 'SandhirFileMonitor.py']
PARENT = ['BackupV10', 'BackupV11', 'DayReadiness', 'reporterV70']
ABS PATH =
E:\Data\ActiveData\SandipanPersonalData\FromNODE06\SoftwareBackups\BackupV11
CURENT = ['Diff.txt', 'Folder2', 'report-templates', 'reports - Copy
(2).html', 'reports - Copy (3).html', 'reports - Copy (4).html', 'reports -
Copy (5).html', 'reports - Copy.html', 'reports.html',
'SandhirFileBackupUtility - Copy.py', 'SandhirFileBackupUtility.py',
'SandhirFileBackupUtility.py - Shortcut.lnk', 'SandhirFileMonitor.py']
PARENT = ['BackupV10', 'BackupV11', 'DayReadiness', 'reporterV70']

I am obviously missing something very simple, but I can't figure this out .
it's been a few days now.

Can someone help? Thanks.

Sandipan
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top