[英]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. 为了将AccountView XML输入文件转换为XML Auditfile Afrekensystemen(现金寄存器),我需要生成没有路径的输出文件名。 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. 但是,
local export documents
声明要求文件名仅由基本名称和扩展名组成。 When you include directory structure in it, it will generate funny file paths like <root path>\\c_\\folder\\...
. 当您在其中包含目录结构时,它将生成有趣的文件路径,例如
<root path>\\c_\\folder\\...
How do I extract the name of the file without directory path and without extension from f.file_path
? 如何从
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: 采用文件路径,例如
c:\\folder\\...\\accountview.xml
,将其分为三部分:
.xml
is put in $2. .xml
都放在$ 2中。 .xml
is another part, but not referencable in the replace string. .xml
是另一部分,但在替换字符串中不可引用。 The $2.xaa
gives me on the file path as output: accountview.xaa
. $2.xaa
在文件路径上为我提供了输出: accountview.xaa
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.