The checking of folder existance is not working...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The checking of folder existance is not working...
# 1  
Old 07-20-2009
The checking of folder existance is not working...

Hi all,

I have the following code:
Code:
if [ -d /home/batch/testing ]; then echo 'folder not exist'; else echo 'folder exist'; fi

The "testing" folder is not exist in /home/batch , but thhe result is 'folder exist'. It seems that the code cannot detect that the folder "testing" not exist.

ANybody know the solution?

thanks.. Smilie

---------- Post updated at 10:31 PM ---------- Previous update was at 10:20 PM ----------

Hi,

There something wrong with my "If-Else" statement... I should put echo 'folder exist' first, not in the else part.

Issue Solved..
thanks for viewing.. Smilie
# 2  
Old 07-20-2009
Code:
if [ -d /home/batch/testing ]; then echo 'folder exists'; else echo 'folder does not exist'; fi

You had it backwards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking of file exist in different folder

Hi All, Seeking for your assistance to compare if the file in working directory is found on the DIR2 directory and if not found move the file in DIR2. ex. WORKING_DIR=/home/dir1/ file1.txt DIR2=/home/admin/users file1.txt what i did was found_nonempty='' for file in... (4 Replies)
Discussion started by: znesotomayor
4 Replies

2. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

3. Shell Programming and Scripting

Error while checking file existance

Kindly help on below script: << i='find ...' if then echo 'File Exists' else echo 'File Does Not Exist' >> If i has some file name then it runs properly but if i has nothing ( blank value) then it throws an error. I dont exactly remember right now but error seems like:... (2 Replies)
Discussion started by: ravigupta2u
2 Replies

4. UNIX for Dummies Questions & Answers

Script for checking the files in a folder

Hi , I am using the below script for checking for a file in a folder. if ; then echo 0 else echo 1 fi Is there any way we can check for files which are starting with GL*.csv.What I am trying to do is , I have to check in a folder for the GL*.csv files if there are any files they I... (6 Replies)
Discussion started by: wangkc
6 Replies

5. Shell Programming and Scripting

Checking the existance of multiple files

I am trying to execute the following command to check the existance of a file (which has a date timestamp on it). If there are more than one file, then also it should give me 'success' result. if then <do some work> else <no files> fi Since there are more than one... (18 Replies)
Discussion started by: vivek_damodaran
18 Replies

6. Web Development

Checking if a folder is empty or not using PHP

Hi, I am sharing this tip with you all.The codes given below will explain /** * Checking a folder is empty or not. * @param string $folderName * $folderName should be folder name or path * @return TRUE/FALSE (If any file or folder found/Empty folder) */ function... (1 Reply)
Discussion started by: elizas
1 Replies

7. Shell Programming and Scripting

checking existance of files and directories

I have a list of files and their directories, starting from a particular location. e.g. temp/new/a.c temp/new/b.c temp/old/a.c temp/old/older/b.c etc. Now I want to check the existence of all these files in the respective directories . I am trying something like cat "fileList" |... (4 Replies)
Discussion started by: herojeett
4 Replies

8. UNIX for Dummies Questions & Answers

Checking file existance by extension

I'm sure this can't be too tough, but. I want to check the existance of file(s) by extension. There may be 0,1,N files. If any files exist, then remove them. Thanks for any insight. (3 Replies)
Discussion started by: niswonp
3 Replies

9. Shell Programming and Scripting

Checking if any folder is opened or not?

Alogorithm: ============= Whenever any user open any specific directory: 1) cd /usr/lib The prompt should show an Alert message like 2) echo "You have opened this folder" How should I write shell script this one?.. It should be irrespective of users and... (11 Replies)
Discussion started by: Niroj
11 Replies

10. UNIX for Dummies Questions & Answers

checking missing files in side a folder

Dear all, Every hour i am receiving several data files to one folder for 24 hours each day.But some times some hours i do not have the files because of some problem.So i want to check the files inside the folder at the end of the day wether how many files i received in each hour like this.so i... (4 Replies)
Discussion started by: Nayanajith
4 Replies
Login or Register to Ask a Question