Check for file with a particular extension in a particular directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check for file with a particular extension in a particular directory
# 1  
Old 05-29-2014
Check for file with a particular extension in a particular directory

Hi,
I have a directory which I am passing in my script as a parameter. Parameter name has been set to $TCH_FILE_DIRECTORY.
I want to know if there's atleast 1 (or more) files in this directory with the extension '.tch'. How can I find this using ksh.
# 2  
Old 05-29-2014
Code:
[ $(ls ${TCH_FILE_DIRECTORY}/*.tch | wc -l) -gt 0 ] && echo "Found at least one file" || echo "No files found"

# 3  
Old 05-30-2014
Regarding Glob

I read at some places about globs. Can globs be used to find out files with any extension in ksh. If yes, how?
# 4  
Old 05-30-2014
Quote:
Originally Posted by Bhavesh Sharma
I read at some places about globs. Can globs be used to find out files with any extension in ksh. If yes, how?
globs is nothing more that the ability for the shell to expand a matched pattern
This is a glob *.tch. The shell will match and expand any string of any length followed by a period, followed by the string tch

What is not working for you?
Why don't you post what you have tried so far?
# 5  
Old 05-30-2014
Quote:
Originally Posted by Bhavesh Sharma
I read at some places about globs. Can globs be used to find out files with any extension in ksh. If yes, how?
What did you read about glob? Did you get the context? the above post also uses them.

Another way

Code:
ls  ${TCH_FILE_DIRECTORY}/*.tch >/dev/null 2>&1 && echo found || echo not found

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find file with extension and excluding directory

Hi, I have an inquiry on how do I use the find command in Solaris Unix to find some file ends with extension : txt, err in the root directory with modified date of 30days and this find command will also need to exclude b directory and its subdirectory. All the files from the above find criteria... (5 Replies)
Discussion started by: snowfrost88
5 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

How to check if something is a file, directory or other?

I want to know how you would go about checking if something is either a file or a directory. mostly for argument validation stuff. I know -d is to see if its a directory but im guessing -f is for files?? (1 Reply)
Discussion started by: Waffles
1 Replies

4. Shell Programming and Scripting

check if a given string is a file or directory

hi i want to know how to do this if the given is /tmp/ and it is a valid directory then it will echo directory if the given is /tmp/file.txt and is a valid file then it will echo file.. thanks! (5 Replies)
Discussion started by: h0ujun
5 Replies

5. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

6. Shell Programming and Scripting

How to check that passed parameters all have the same extension?

$ ls monkey.txt banana.csv tree.txt $ myscript monkey.txt tree.txt All extensions ARE alike. $ myscript *txt All extensions ARE alike. $ myscript monkey.txt banana.csv All extensions are NOT alike. $ myscript * All extensions are NOT alike. My brain has given up; what's the simplest... (11 Replies)
Discussion started by: cs03dmj
11 Replies

7. Shell Programming and Scripting

How do i check whether a file has extension?

Hi, How do i check whether a file has extension? I need to code a script that will check whether a file has extension or not. Say a file Rpt200 If the file doesn't have an extenion, I need to rename the file with .txt extension. For example Rpt200 will become Rpt200.txt Please advice. ... (2 Replies)
Discussion started by: sunday8
2 Replies

8. Shell Programming and Scripting

Check file extension

Hi , I am FTPing the file. Once the file is FTPied I need to check whether that file currently transferred is of .xls and I need to convert the same to a flat file. What command to use to find the extension of the file?. Thanks Mahalakshmi.A (6 Replies)
Discussion started by: mahalakshmi
6 Replies

9. Programming

how to check if directory/file exist using c/c++

Hi there, how to check if directory/file exist using c/c++ under linux/unix. Thanks. Steven (2 Replies)
Discussion started by: steven88
2 Replies

10. Shell Programming and Scripting

how to check if directory/file exist using c/c++

Hi there,, how to check if directory/file exist using c/c++ under unix/linux? I can use access() under Window MFC. Thanks. Steven (1 Reply)
Discussion started by: steven88
1 Replies
Login or Register to Ask a Question