|
Answer» Hi there
I am attempting to incorporate a FOR command into a batch file to run Altova command line stuff. MapForce to create XML files and AltovaXML to VALIDATE the newly created XML files.
I've hit a wall and this is what i have so far, and it's running the MapForce part, but returning an error on the AltovaXML part.
=================================================================== @echo off CLS SETLOCAL SET MFD=C:\MDL\MFD_Mapping_Working SET XML=C:\MDL\XML_Output_Working SET MapForce="C:\Program Files\Altova\MapForce2007\MapForce.exe" SET AltovaXML="C:\Program Files\Altova\AltovaXML2007\AltovaXML.exe"
CD %MFD%
FOR %%A in (*.mfd) do ( %MapForce% %%A /BUILTIN %XML%\%%A /LOG %XML%\%%A\%%A.log %AltovaXML% /VALIDATE %XML%\%%A\%%A.xml ) ) ENDLOCAL pause CLS ===================================================================
In the %MFD% folder I have a bunch of MFD files all named differently, I'll use the following, Charges_Mobile_NRC.mfd
A folder is created in the %XML% with the same name of the file, one folder for each file, Charges_Mobile_NRC.mfd
So far so good. MapForce runs and creates 2 files in the above folder called, Charges_Mobile_NRC.mfd.log Charges_Mobile_NRC.xml
This is now where I am having problems. Problem 1: I get an error from AltovaXML that says,
Error: C:\MDL\XML_Output_Working\Charges_Mobile_NRC.mfd\Charges_Mobile_NRC.mfd.x ml was not found.
I can't find a way to strip the .mfd from the variable for the AltovaXML section
Problem 2: MapForce can take from 5 seconds to 3-4 minutes to create the xml files. How can I make the above code check and wait until the xml file is created without setting a fixed time delay for all files (I don't see the need to wait something like 10 minutes if the xml file is there in 10 seconds).
Currently it takes about 8-10 hours to run though all of the mdf files and create xml from them, so validating along the way is the ideal solution instead of having to wait 8-10 hours to see if it validates ok.
I know there's a lot to read, but you people like a challenge don't you.
Thanks in advance.Code: [Select] In XP, substitution of FOR variable references has been improved
%~I - expands %I removing any surrounding quotes (") %~fI - expands %I to a fully qualified path name %~dI - expands %I to a drive letter only %~pI - expands %I to a path only %~nI - expands %I to a file name only <------------------------------------------------ %~xI - expands %I to a file extension only %~SI - expanded path contains short names only %~aI - expands %I to file attributes of file %~tI - expands %I to date/time of file %~zI - expands %I to size of file
in other words if %%a is a filename plus dot plus extension, %%~na is just the filename, dot and extension removed.
So try this...
change this line
%AltovaXML% /VALIDATE %XML%\%%A\%%A.xml
to this
%AltovaXML% /VALIDATE %XML%\%%A\%%~nA.xml
It worked in a trial batch I just ran.
Quote Problem 2: MapForce can take from 5 seconds to 3-4 minutes to create the xml files. How can I make the above code check and wait until the xml file is created without setting a fixed time delay for all files (I don't see the need to wait something like 10 minutes if the xml file is there in 10 seconds).
to see if any particular file is in use by another program, you can use handle.exe, part of the XP Reskit, free from Microsoft at
http://www.microsoft.com/technet/sysinternals/SystemInformation/Handle.mspx
Download it and put in somewhere on your PATH
eg to see if afilename.zzz is in use
handle | findstr /i "afilename.zzz"> nul && echo is in use
So you could do this
:wait handle | findstr /i "%XML%\%%A\%%~A.xml" && goto wait
%AltovaXML% /VALIDATE %XML%\%%A\%%~A.xml
A lot depends if MapForce creates the xml file STRAIGHT away, and releases it when it has finished, or if it just writes it out at the end of its processing...
|