1

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?

4

1 回答 1

2

使用以下查询,我现在得到一个没有目录的文件名:

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

那个部分:

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

取一个文件路径,例如c:\folder\...\accountview.xml,将其分成三部分:

  • 从开始到最后发现的正斜杠或反斜杠放在 $1 中。
  • 在斜线之后直到出现尾随.xml被放入 $2。
  • 尾随.xml是另一部分,但在替换字符串中不可引用。

$2.xaa了我文件路径作为输出:accountview.xaa.

于 2016-11-30T08:05:54.067 回答