A couple of you commented that I should be using os.path.join.
Accordingly, I rewrote my code. Unfortunately, I still have the same
problem. the following code snippet
print os.getcwd() #verify what the current directory IS.
fid = os.path.join(InputDirectory, x)
print fid, os.path.exists(fid)
Results.SetOriginal(os.path.getsize(os.path.join(InputDirectory , x)))
# replace above
Results.SetOriginal(os.path.getsize(fid))
y = str(x.split('.')[0]) + '.rk'
# replace above
y = os.path.splitext(fid)[0] + ".rk"
fid2 = os.path.join(InputDirectory, y)
print fid2, os.path.exists(fid2)
print InputDirectory, y # delete above
raw_input() # what is this doing?
Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y)))
# replace above
Results.SetArchive(os.path.getsize(fid2))
Output upon execution is as follows:
Test_Data\ Book1.rk
Traceback (most recent call last):
File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py",
line 60,
in ?
Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y)))
File "C:\Python24\lib\ntpath.py", line 229, in getsize
return os.stat(filename).st_size
OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.rk'
What am I doing wrong?
Does "Test_Data\Book1.rk" EXIST (ignore the double \ in the
message, that's just Python's escaping of the slash, as that is what
would be needed for you to type it in a Python statement:
x = "Test_Data\\Book1.rk"
The os.path.exists(), along with the os.getcwd() call, should show where
it is looking, and if the file is there.
--