Home » Infrastructure » Unix » How to get a list of files ?
How to get a list of files ? [message #124385] Fri, 17 June 2005 17:28 Go to next message
jef1
Messages: 6
Registered: June 2005
Junior Member
Hello,
I use Oracle 9i on HP-UX platform. Oracle directories have been defined that map to Unix directories. I would like to know if it's possible to retrieve a list of all the files present in a oracle directory. Is there a built in stored procedure or a function in a PL/SQL package that allow that ?
Thanks a lot.
Re: How to get a list of files ? [message #124397 is a reply to message #124385] Fri, 17 June 2005 21:16 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
There is no built-in, but it can be done easily with a Java stored procedure:

http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:439619916584
Re: How to get a list of files ? [message #124428 is a reply to message #124397] Sat, 18 June 2005 06:41 Go to previous messageGo to next message
jef1
Messages: 6
Registered: June 2005
Junior Member
Hello,
thanks for the reply. The Java solution is attractive and interesting but in term of performance is it the really best one ? I 'm afraid it could consume lot of memory and could be not fast enough. Ideas about that ? Can the same be done with external procedure written in C programming language.
Thnaks a lot.
Re: How to get a list of files ? [message #124433 is a reply to message #124428] Sat, 18 June 2005 08:16 Go to previous messageGo to next message
William Robertson
Messages: 1643
Registered: August 2003
Location: London, UK
Senior Member
A simpler alternative might be to have a cron job construct a file list every so often, and define an external table to read that. The script called from cron would be something like:

#!/bin/ksh

find . -type f -newer files_xt.dat >/dev/null && \
for f in test*.dat
do
        ls -l $f | read privs nodes owner group size month day time filename
        print ${filename},${owner},${group},${size},${privs},\"$(date +%Y)-${month}-${day} ${time}\"
done > files_xt.dat

which would produce a file like this

test20050101.dat,williamr,staff,2,-rw-r--r--,"2005-Jun-11 17:51"
test20050102.dat,williamr,staff,2,-rw-r--r--,"2005-Jun-11 17:50"
test20050103.dat,williamr,staff,2,-rw-r--r--,"2005-Jun-12 09:41"
test20050104.dat,williamr,staff,2,-rw-r--r--,"2005-Jun-13 10:21"
test20050105.dat,williamr,staff,2,-rw-r--r--,"2005-Jun-14 14:33"

and the external table could be defined something like:

CREATE TABLE files_xt
( filename         VARCHAR2(50)
, permissions      VARCHAR2(10)
, owner            VARCHAR2(10)
, owner_group      VARCHAR2(7)
, file_date        DATE )
ORGANIZATION EXTERNAL
( TYPE oracle_loader
  DEFAULT DIRECTORY william_test
  ACCESS PARAMETERS
  ( RECORDS DELIMITED BY newline
    LOAD WHEN (1:1) != "#"
    BADFILE 'files_xt.bad'
    DISCARDFILE 'files_xt.dis'
    LOGFILE 'files_xt.log'
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    ( filename
    , owner
    , owner_group
    , nodes
    , permissions
    , file_date    DATE "YYYY-Mon-DD HH24:MI" )
  )
  LOCATION ('files_xt.dat')
)
REJECT LIMIT UNLIMITED;

and it would look this this in the database:

SQL> desc files_xt
 Name                          Null?    Type
 ----------------------------- -------- --------------------
 FILENAME                               VARCHAR2(50)
 PERMISSIONS                            VARCHAR2(10)
 OWNER                                  VARCHAR2(10)
 OWNER_GROUP                            VARCHAR2(7)
 FILE_DATE                              DATE

SQL> col filename format a20
SQL> SELECT * FROM files_xt;

FILENAME             PERMISSION OWNER      OWNER_G FILE_DATE
-------------------- ---------- ---------- ------- -----------
test20050101.dat     -rw-r--r-- williamr   staff   11-JUN-2005
test20050102.dat     -rw-r--r-- williamr   staff   11-JUN-2005
test20050103.dat     -rw-r--r-- williamr   staff   12-JUN-2005
test20050104.dat     -rw-r--r-- williamr   staff   13-JUN-2005
test20050105.dat     -rw-r--r-- williamr   staff   14-JUN-2005

5 rows selected.

[Updated on: Sat, 18 June 2005 08:17]

Report message to a moderator

Re: How to get a list of files ? [message #124473 is a reply to message #124428] Sat, 18 June 2005 22:07 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
The AskTom link I provided answers your question about the external procedure. You can search that site for examples.
Previous Topic: WHAT SHOULD BE THE MINIMUM HARDWARE REQUIREMENT TO CONFIGURE ORACLE ON UNIX SERVER
Next Topic: How to get number of rows deleted from SQL in a shell script
Goto Forum:
  


Current Time: Fri Nov 29 09:22:57 CST 2024