Verify if filename exists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Verify if filename exists
# 1  
Old 09-13-2016
Verify if filename exists

Hi,

I have a variable returned from Oracle SQL Function which holds file names.

I would like to test if all the file names mentioned in the string exists in a directory. If all the files exists print "exists", even if one file does not exists print "Does not exists".

e.g.
Code:
 l_FILENAMES="file1 file2 file3 file4"


Regards,
Pointers

Last edited by rbatte1; 09-13-2016 at 09:36 AM.. Reason: Add CODE tags
# 2  
Old 09-13-2016
What have you tried?

You could:-
Code:
ls -1 $l_FILENAMES

Those that exist will be displayed and those that do no will return an error.

If you want to be a bit smarter, you can:-
Code:
for file in $l_FILENAMES
do
   if [ -f $file ]
   then
      printf "File %s exists" "$file"
   else
      printf "File %s is missing" "$file"
   fi
done

You can adjust this to not print anything but keep a note if any does not exist and then display your choice of message at the end.


I hope that this helps. Let us know how you get on and if you get stuck I'm sure we can suggest something else.


Robin
# 3  
Old 09-13-2016
You could also try:
Code:
ls $l_FILENAMES >/dev/null 2>&1 && echo exists || echo 'Does not exist'

# 4  
Old 09-14-2016
Since you are using Oracle anyway, Oracle has a built in package called utl_file. You can use the FGETATTR
Procedure in utl_file to check if the file exists and handle the errors if a file does not exist. You just need to
have a database directory point to where the files are.

UTL_FILE
This User Gave Thanks to gandolf989 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Waiting for wildcard filename to exists in while loop

Hi Experts, We are developing a script which will wait for the trigger file(with datetime in the trigger file name). But the problem is when I use 'while' loop to wait for the file, it waits for the filename with wilcard in it that is wait for 'Trigger*.done' file. :eek: Below is the script ... (4 Replies)
Discussion started by: Amey Joshi
4 Replies

2. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

3. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. Shell Programming and Scripting

Verify File exists and execute command

Hi, I am trying to verify that a file exists within an alternate directory. If the file exists, it will execute a copy command...if it does not, it should exit the script. I tried the <test> command and the but keep coming up with syntax errors. I am coding in C Shell and the file... (5 Replies)
Discussion started by: CKT_newbie88
5 Replies

6. AIX

verify command

Guy's I have script doing many steps as the below ... ############# ## step1# mount all Files system mount all ## step2# Start the application /app/appsh ############# but some time mount points will not be mounted completely so that will give an error if the next step started... (1 Reply)
Discussion started by: Mr.AIX
1 Replies

7. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

8. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

9. Shell Programming and Scripting

verify if a process exists (ps)

hi I want to verify that a process exists. if the process exists, then it means the service is up. ps -ef | grep monito returns an entry if the service is up. how to translate that in a shell script?? many thanks (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

10. Shell Programming and Scripting

test if a filename exists with specified string (ksh)

I'm trying to do a simple if statement that tests if a filename exists with a user specified string. So say I have these files: Assigned_1day_after_due_chuong Assigned_1day_after_due_gallen Assigned_1day_after_due_heidenre and i'm running a script and want to know if a... (6 Replies)
Discussion started by: bob122480
6 Replies
Login or Register to Ask a Question