简体   繁体   中英

Retrieve file name from path with Invantive SQL

For a conversion of AccountView XML input files to XML Auditfile Afrekensystemen (Cash Registers) I need to generate an output file name without a path. The query is:

select f.file_path file_path_src
,      replace(f.file_path, '.xml', '.xaa') file_path_tgt
,      xmltransform(cnt.file_contents, xsl.file_contents) xaa_contents
from   files('${rootpath}\input', '*.xml')@os f
join   read_file_text(f.file_path)@os cnt
on     1=1
join   read_file_text('${scriptpath}\convert-account-view-to-xaa.xsl')@os xsl
on     1=1

local export documents in xaa_contents to "${rootpath}\output" filename column file_path_tgt

However, the local export documents statement requires the file name to consist solely of the base name and the extension. When you include directory structure in it, it will generate funny file paths like <root path>\\c_\\folder\\... .

How do I extract the name of the file without directory path and without extension from f.file_path ?

Using the following query I now get a file name without directory:

select f.file_path file_path_src
,      regexp_replace(f.file_path, '^(.*[\\/]|)(.*).xml$', '$2.xaa') file_path_tgt
,      xmltransform(cnt.file_contents, xsl.file_contents) xaa_contents
from   files('${rootpath}\input', '*.xml')@os f
join   read_file_text(f.file_path)@os cnt
on     1=1
join   read_file_text('${scriptpath}\convert-account-view-to-xaa.xsl')@os xsl
on     1=1

The part:

regexp_replace(f.file_path, '^(.*[\\/]|)(.*).xml$', '$2.xaa')

takes a file path such as c:\\folder\\...\\accountview.xml , splits it into three parts:

  • From start till the last found forward or backward slash is put in $1.
  • After the slash till the occurrence of a trailing .xml is put in $2.
  • The trailing .xml is another part, but not referencable in the replace string.

The $2.xaa gives me on the file path as output: accountview.xaa .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM