Name: Vikram Date: March 6, 2001 at 07:34:32 Pacific Subject: How do I check if a directory exists?
Comment:
I am writing a program in Java that creates directories in the UNIX platform (I am using the Runtime.exec("...") call, for wihch my parameter will be a UNIX command such as mkdir, rmdir etc.
Now waht I want to do is, first ask a user where he wishes to store the files, and check if that directory exists. If it does exist, then I just save those files there (I have the code for the saving bit), else I create the directory and then save the files in there. So I first need to check the validity and the existence of the directory the user wishes to create. IS there a UNIX command that I can use to see if a directory exists?
test checks, if /directory exist and if it is a directory (switch -d). the construct "&& action" is executed, if the test results in ok (returncode 0) see the man-page for test.