在目录中查找文件列表时出现问题 [英] problem in finding list of files in directory

查看:88
本文介绍了在目录中查找文件列表时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索特定文件夹中所有文件的列表,其中包括oracle窗体和菜单以及报告和一些txt文件...

I want to retrieve list of all file in a specific folder that included oracle form and menu and report and some txt file...

您是否知道如何以ORACLE形式检索这些数据,并将其自动插入到我的数据块中?

Do you have any idea how I can retrieve these data in ORACLE form, and insert them into my data block, automatically?

我使用的是Oracle 6.0版.

I use oracle form 6.0.

推荐答案

我遵循以下原则进行了操作:

I did something along these lines:

为您要列出的目录创建一个Oracle目录:

Create an Oracle directory for the directory you want to list:

create or replace directory YOURDIR
  as '\path\to\your\directory';

建立一个临时表:

create global temporary table DIR_LIST
(
  FILENAME VARCHAR2(255),
)
on commit preserve rows;
grant select, insert, update, delete on DIR_LIST to PUBLIC;

您将需要一个Java存储过程:

You'll need a java stored procedure:

create or replace and compile java source named dirlist as
import java.io.*;
  import java.sql.*;
  import java.text.*;

  public class DirList
  {
  public static void getList(String directory)
                     throws SQLException
  {
      File dir = new File( directory );
      File[] files = dir.listFiles();
      File theFile;

      for(int i = 0; i < files.length; i++)
      {
          theFile = files[i];
          #sql { INSERT INTO DIR_LIST (FILENAME)
                 VALUES (:theName };
      }
  }

  }

以及调用Java的PL/SQL可调用过程:

And a PL/SQL callable procedure to invoke the java:

CREATE OR REPLACE PROCEDURE get_dir_list(pi_directory IN VARCHAR2)
AS LANGUAGE JAVA
name 'DirList.getList(java.lang.String)';

最后,在表单中调用过程get_dir_list将用目录中的文件填充表,然后您可以将其读入表单块.

Finally, calling the procedure get_dir_list inside your form will populate the table with the files in your directory, which you can then read into your form block.

Java代码直接来自汤姆·凯特(Tom Kyte)的书(不记得是哪本书).

The java code came straight out of a Tom Kyte book (don't recall which one).

实际上,所有代码都从

Actually, all the code is pretty much lifted from this AskTom thread.

这篇关于在目录中查找文件列表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆