Using pl/sql how do I locate a file in a directory and move the file?
+2
A:
To test if a file exists, you can use UTL_FILE.fGetAttr
. Docs
For example:
DECLARE
l_file_exists BOOLEAN;
l_file_len NUMBER;
l_blocksize BINARY_INTEGER;
BEGIN
utl_file.fgetattr(
location => 'MYDIRECTORY',
filename => 'myfilename.ext',
fexists => l_file_exists,
file_length => l_file_len,
block_size => l_blocksize);
IF l_file_exists THEN
dbms_output.put_line('File found, size=' || l_file_len);
ELSE
dbms_output.put_line('File not found.');
END IF;
END;
To rename a file, you can use UTL_FILE.fRename
. Docs
For example:
BEGIN
UTL_FILE.FRENAME (
src_location => 'FROMDIRECTORY',
src_filename => 'filename.ext',
dest_location => 'TODIRECTORY',
dest_filename => 'filename.ext',
overwrite => FALSE);
END;
Jeffrey Kemp
2010-08-30 02:24:39