Displaying files in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Displaying files in a directory
# 1  
Old 03-14-2007
Displaying files in a directory

Dear Experts,
I am new to UNIX and I have a script below and in this test case I am reading the names of the files in the present directory into a variable and then looping through each file name and displaying the name back to the screen. The problem I have is although there are 5 files in the directory, it only ever displays the name of the first file and then stops. Can you assist?
Many thanks,
Mark

#!/bin/csh
set files = `ls`
#
foreach file ( $files )
echo 'File name:' $file
end
# 2  
Old 03-14-2007
Code:
#!/bin/csh
foreach file ( * )
echo 'File name:' $file
end

# 3  
Old 03-14-2007
Many thanks for your feedback. What are really require is to do something like this:

set files = `ls -a /file_path_of_files_to_process_dir`

set archive = '/archive_dir'

foreach file ( $files )

open an sqlplus connection

exec my_custom_PL/SQL_package.custom_procedure($file)

close sqlplus connection

mv $file $archive

end

Therefore, in this example I wish to pick up files from a different directory and then take the file name and use it in a parameter call to a custom PL/SQL procedure and then once processed, move the file to an archive directory. I wish to repeat this until no more files exist. What would be the UNIX code (ignor the sqlplus and PL/SQL component) to retrieve files from another location and then process?
Thanks for your assistance,
Mark
# 4  
Old 03-14-2007
a pointer,
Smilie

Code:
DIR=/path/where/files/are/available/
 ARCHIVEDIR=/path/to/archive/files/
 
 ls -1 $DIR | while read file
 do
   echo "Processing file $file"
   <your process here>
   echo "Processed file $file"
   mv $DIR$file $ARCHIVEDIR
   compress $ARCHIVEDIR$file
 done

# 5  
Old 03-14-2007
I've just tested that and it works for me. That is a great help - many thanks for your time!
Mark
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Directory not displaying (strange)

Hi All. I am facing a strange scenario (c13:pq1:/pq1/buffer>) ll ../dataCS/* ls: cannot access ../dataCS: No such file or directory (c13:pq1:/pq1/buffer>) cd ../dataCS (c13:pq1:/pq1/dataCS>) ll * -rw-rw-r-- 1 pq1 pq10 Mar 1 13:43 test (c13:pq1:/pq1/dataCS>) ll ../dataCS/* -rw-rw-r--... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. Shell Programming and Scripting

Perl: Comparing to two files and displaying the differences

Hi, I'm new to perl and i have to write a perl script that will compare to log/txt files and display the differences. Unfortunately I'm not allowed to use any complied binaries or applications like diff or comm. So far i've across a code like this: use strict; use warnings; my $list1;... (2 Replies)
Discussion started by: dont_be_hasty
2 Replies

3. Shell Programming and Scripting

Displaying Files Problem

To match all filename comprising at least three characters the first character is numeric and the last character is not alphabetic (2 Replies)
Discussion started by: polineni
2 Replies

4. Shell Programming and Scripting

Displaying Files Problem

To match all filename comprising at least three characters not beginning with a dot (1 Reply)
Discussion started by: polineni
1 Replies

5. UNIX for Dummies Questions & Answers

Displaying the current working directory in prompt

Hi, I want that the prompt that is being displayed (i.e $ sign) should display always the current directory I am working in instead of that $ sign example: as we use PS1=patric and the prompt changes from $ to patric OR if we write the command PS1=`pwd` it will display the current... (5 Replies)
Discussion started by: premjotsingh
5 Replies

6. Shell Programming and Scripting

Displaying difference of 2 files

Hi All, Got this 2 file namely a.txt and b.txt, i want to know how to extract the difference between the two files, the output will be written to a file. e.g. >>a.txt<< Nokia 1100 Nokia 1200 Nokia 1300 Nokia 1400 Nokia 1500 Nokia 1600 Nokia 1700 Nokia 1701 Nokia 1702 Sagem 1100... (3 Replies)
Discussion started by: shtobias
3 Replies

7. Shell Programming and Scripting

Displaying a list of files

Given a set of log files like trail.<timestamp> that are generated hourly, how do I get the list of files created for the current date, using shell script? Can anyone please help me?the format of the trace file is trail.YYYYMMDDhh I also need to know how I can "grep" for a particular word in these... (2 Replies)
Discussion started by: ggayathri
2 Replies

8. Shell Programming and Scripting

displaying 3 directory listings in 3 separate columns.

i having problems figuring out how to 'read' in 3 different directory listings and then display them on the screen into 3 separate columns. i thought i could use a 'for' loop to grab each directory and then assign a unique variable to each line 'read' in. of course, as you experts all know,... (16 Replies)
Discussion started by: mjays
16 Replies

9. Shell Programming and Scripting

Displaying files

I am beginner to UNIX. I wanted to display 5 filesname with size from BIN directory. The order of display should be descending order in size. Can help me. (1 Reply)
Discussion started by: giridher2000
1 Replies

10. UNIX for Dummies Questions & Answers

displaying directory in html

How would i in a csh script get it to display all the files in the current directory in html? (9 Replies)
Discussion started by: adel66
9 Replies
Login or Register to Ask a Question