Help Need In Coding
Thomas Weholt
thomas at gatsoft.no
Thu Oct 18 04:27:03 EDT 2001
Look into the module os for this, mostly the stuff in os.path
to check if a file exists, if it's a file or a folder, do something like
this :
import os
file2check = '/someplace/somefile.java'
if os.path.exists(file2check) and os.path.isfile(file2check): print "It's a
file allright"
use os.getcwd() to get the current working dir, and something like this to
check for a specified file in this dir :
if os.path.exists(os.path.join(os.getcwd(), 'yourfilename.java')): print
"The file exists in the current dir"
os.path.join() joins a folder and a file, using correct path-seperator for
you os etc.
use os.path.walk ( might be os.walk ) to traverse a folder-tree.
This should get you started. Didn't understand the rest of your question
though ...
Thomas
"Alec D. Cheah" <cheah at comline.com.my> wrote in message
news:4783f0eb.0110172313.ef7755e at posting.google.com...
> i'm using Python 2.1
>
> How do verified from input the variable entered is a file or a path
> and how do you check whether it exist or not??
>
> now let say ... i just specified input a value "xxx.java" i just want
> to check whether it exist in a current directory or subdirectory of
> current directory depending on how many directory level you have. if
> not a file then check whether it a directory????
>
> In this case it will do a searching base on the input value.
>
> Help...
>
> Newbie on Python....
More information about the Python-list
mailing list