Help Need In Coding

Thomas Weholt thomas at
Thu Oct 18 10:27:03 CEST 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/'

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(), '')): 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 ...


"Alec D. Cheah" <cheah at> wrote in message
news:4783f0eb.0110172313.ef7755e at
> 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 "" 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