LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-05-2008, 10:24 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
detecting if a directory exists


Hi all,
can anyone help me with this problem (I have very little understanding of Linux commands). I have a makefile which I use a rm $(OBJECT_FOLDER) I then create it using mkdir, however the first time I run it the object folder does not exist so my makefile reports an error.

Is there a way I can detect if the folder exists? A sort of "if folder then remove old folder"

Thanks in advance
 
Old 10-05-2008, 11:24 AM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
in bash you can use something like "if [ -d /some/folder/ ]" which is true if the file exists and is a folder
 
Old 10-05-2008, 11:31 AM   #3
drchuck
Member
 
Registered: May 2007
Posts: 61

Rep: Reputation: 17
even simpler still:
Code:
[[ -e $DIR ]] && rmdir $DIR
Have a look at the advanced bash shell scripting guide. It's all in there, and then some.
 
Old 10-06-2008, 09:48 AM   #4
toshiro
LQ Newbie
 
Registered: Jan 2003
Distribution: Debian, Ubuntu, Solaris
Posts: 24

Rep: Reputation: 0
Quote:
Originally Posted by drchuck View Post
even simpler still:
Code:
[[ -e $DIR ]] && rmdir $DIR
Have a look at the advanced bash shell scripting guide. It's all in there, and then some.

I think is better to use -d instead of -e (-e only asserts that a file exists, but don't tell whether it's a directory, -d does that).

Code:
[[ -d $DIR]] && rmdir $DIR
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find if a directory exists in a gawk script duparcmeur Linux - Newbie 2 04-02-2008 01:57 PM
wine: exists lstat socket : No such file or directory hisnumber666 Linux - Software 1 05-02-2006 02:35 AM
/usr/bin/emacs: No such file or directory...yet it exists andeity Linux - General 6 04-16-2006 08:54 PM
no such file or directory exists when trying to execute a exe ryedawg Linux - Software 5 12-05-2005 05:42 AM
Bash scripting and trying to determine whether a directory exists? obelxi Programming 9 04-18-2005 11:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration