error sending path to Win OS

Earl Eiland eee at
Mon Mar 14 14:54:02 CET 2005

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

Results.SetOriginal(os.path.getsize(os.path.join(InputDirectory , x)))
y = str(x.split('.')[0]) + '.rk'
print InputDirectory, y
Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y)))

is executed from the command line with
C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\
Test_Data\ Test_Output\Results
Test_Data\ Book1.rk, where InputDirectory (in the above snippet) =
'Test_Data\' (I've also tried 'Test_Data', with the same results).

x (in the above snippet) is an element of the list generated by

Output upon execution is as follows: 
Test_Data\ Book1.rk

Traceback (most recent call last):
  File "C:\Documents and Settings\eeiland\Thesis\Plan2\",
line 60,
in ?
    Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y)))
  File "C:\Python24\lib\", 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?


On Sat, 2005-03-12 at 15:16, Michael Hoffman wrote:
> Earl Eiland wrote:
> > os.path.getsize(Inputdirectory + '\\' + Filename) works, but
> > os.path.getsize(Inputdirectory + '\\' + Filename.split('.') + '.ext')
> > Fails reporting "no such file or directory
> > InputDirectory\\Filename.ext".
> No, that should be a TypeError. This will be easier if you copy and
> paste your Python session instead of making stuff up.
> > os.path.getsize(Inputdirectory + r'\' + Filename.split('.') + '.ext')
> > generates a syntax error.
> 'r"\" is not a valid string literal (even a raw string cannot end in an
> odd number of backslashes). Specifically, a raw string cannot end in a
> single backslash (since the backslash would escape the following quote
> character). Note also that a single backslash followed by a newline is
> interpreted as those two characters as part of the string, not as a
> line continuation.'
> -- 
> Michael Hoffman

More information about the Python-list mailing list