By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,171 Members | 776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,171 IT Pros & Developers. It's quick & easy.

checking for when a file or folder exists, typing problems?

P: n/a
Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\projects"):

and that works fine.

If I change it to be
if exists(thepath):
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks
--
Bryan Rasmussen

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Bryan,

Here's a potential idea. Try converting the variable to a string by
using the following syntax:
thePath = str(thePathArg)
This will convert the current variable type to a string, which follows
the data type syntax that you have specified at the beginning of your
message.

Hope this helps,

Brian :-)
---
Bryan Rasmussen wrote:
Hi
I have a little program that is importing from os.path import exists, join,
isdir, normpath, isfile
at one point in my program I check if a file exists using
if exists("c:\projects"):

and that works fine.

If I change it to be
if exists(thepath):
where thepath is a commandline argument it does not work fine.

Note that the commandline is c:\projects and when I print thepath to check what
is going on it prints
c:\projects

The only thing I can assume is that there is some sort of typing problem going
on here, but then it should go ahead and give an error then if it's getting
something unexpected obviously.

Any help on what this error is?

Thanks

Jul 19 '05 #2

P: n/a
Bryan Rasmussen wrote:
... at one point in my program I check if a file exists using
if exists("c:\projects"):


You should not be using a backslash in non-raw-string source to
mean anything but "escape the next character." The above should
either be written as:
if exists(r"c:\projects"):
or:
if exists("c:\\projects"):

I suspect you problem has to do with this difference, but perhaps not.
Give exact short code that actually demonstrates the problem.

--Scott David Daniels
Sc***********@Acm.Org
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.