VB Script to Rename Files?
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!
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:
@echo off
setlocal enabledelayedexpansion
FOR %%i IN (*.htm) DO (
SET basename=%%~ni
SET basename=!basename: =_!
java -jar saxon.jar -o:"..\Front_Matter\!basename!.xml" "%%i" "C:\Documents and Settings\Robert\Desktop\xsl\htm2xml.xsl"
)
Set fso = CreateObject("Scripting.FileSystemObject")
set oFldr = fso.getfolder("N:\Groups\TestGroup\UPS\")
for each ofile in oFldr.Files
if lcase(fso.GetExtensionName(ofile.Name)) = "txt" then
fso.MoveFile ofile.Path, ofile.ParentFolder & "\HRSC100.txt"
Exit for
end if
Next
*if you want vbscirpt then above will work*
精彩评论