VB脚本重命名文件?
我编写了一个非常简单的批处理脚本,它将为我执行 XSLT 转换,将一堆 html 文件转换为 xml 文件:
FOR %%i IN (*.htm) DO java -jar saxon.jar -o:"..\Front_Matter\%%i.xml" "%%i" "C:\Documents and Settings\Robert\Desktop\xsl\htm2xml.xsl"
XSLT 工作正常,但只是创建的文件没有所需的文件名,例如例如,如果原始文件名是“Happy Christmas.htm”,我希望输出的xml名为“Happy_Christmas.xml”,所以只有两件事,首先是去掉原始的.htm部分文件名,二是用下划线替换空格。
当前生成的文件名很难看,例如:“Happy Christmas.htm.xml”。
提前致谢!
I've written a very simple batch script that will do an XSLT transform for me, to translate a bunch of html files to xml files:
FOR %%i IN (*.htm) DO java -jar saxon.jar -o:"..\Front_Matter\%%i.xml" "%%i" "C:\Documents and Settings\Robert\Desktop\xsl\htm2xml.xsl"
The XSLT works fine, but just the file gets created doesn't have the desired file name, for example, if the original file name is "Happy Christmas.htm", I want the output xml to be called "Happy_Christmas.xml", so there are only just two things, first is to get rid of the .htm part of the original file name, the second is to replace the space by underscore.
The current resulting file name is ugly, like: "Happy Christmas.htm.xml".
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
%%~ni
而不是%%i
提取不带扩展名的基本文件名。使用
%var: =_%
语法将var
变量值中的空格替换为下划线。所以,基本上,你需要这样的东西:
Use
%%~ni
instead of%%i
to extract the base file name without extension.Use the
%var: =_%
syntax to replace spaces in the value of thevar
variable with underscores.So, basically, you need something like this: