checking existance of files and directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking existance of files and directories
# 1  
Old 04-28-2009
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" | xargs -i set myfile = {}
if(-e $myfile){print "file Exist $myfile"}


It gives some error, anybody help me !!
# 2  
Old 04-28-2009
Try this

====code====
while read line
do

ls $line
if [ $? -eq 0 ]
then
echo "$line exists"
else
echo "$line Does not exist "
fi


done < FileList
# 3  
Old 04-28-2009
Hi Amit,

I am not knowing exactly how to try your code.Smilie I am new to UNIX.
Some more info is, i am using CSH. and the the list of the filenames/directories are in a file "fileList"..
Can you give me the exact code which I can directly run in my c shell.

Thanks in Advance..
# 4  
Old 04-28-2009
The FileList contains the path of your file
> cat Filelist
temp/new/a.c
temp/new/b.c
temp/old/a.c
temp/old/older/b.c

So the script will read the file FileList line by line and check if the file is there in the path
then it will print if the file exists or not.

I hope this clears your doubt . I have executed it in ksh
# 5  
Old 04-28-2009
Code:
while read file;do
if [ -f $file ];then
	:
else
	echo "$f not exists"
fi
done < a.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

4. UNIX for Dummies Questions & Answers

Checking if multiple directories exist

I need to create multiple directories if those directories do not exist already. How would you go by doing this. What I have so far. array=(one two three) for I in ${array} do if ] then mkdir ${I} fi doneI have a good feeling this is done incorrectly. The error I am... (2 Replies)
Discussion started by: jrymer
2 Replies

5. Shell Programming and Scripting

how to check existance of multiple directories

Hi, I would like to check whether all the directories exists or not. I tried the below but it gives some error. below is the excerpt from my original script 24 #Check if the required directories are exists 25 dirExists() { 26 27 if 28 then 29 echo "required... (1 Reply)
Discussion started by: lookinginfo
1 Replies

6. 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

7. Shell Programming and Scripting

The checking of folder existance is not working...

Hi all, I have the following code: if ; 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... (1 Reply)
Discussion started by: suigion
1 Replies

8. Shell Programming and Scripting

checking textfile exists or not in all directories

Hai All, please help me in solving this assignment!!! i need a unix script that has to check the text file exists or not in all directories and sub directories if textfile exists display the directory path else display does not exists!! example: kamal.txt that i want to search if the... (5 Replies)
Discussion started by: G.K.K
5 Replies

9. 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
Login or Register to Ask a Question