Trying to conditionally change a file path in a windows batch script -


I have a simple script that launches XML file path in Notepad ++

Unfortunately The generated file path is incorrect for some files and I am trying to compensate for this in the script (the ideal correction path is clearly to solve the problem but this is not the option at the moment).

Here I am sorry for a very new code for batch scripts ...

  set / p filePath = enter file path: if "% FilePath% "==" 1 "Geto xml menu and if"% filePath% "==" file: //path/of/file/*/*/*/*/A/*.XML "set filepath =" file : // path / k / file / * / * / * / * / b / * .xml "goto openxml  

I get the file path variable in the way of the rest from user input Would like to, but at the moment it is clearly set Path along with wildcard is also such a problem where I have stated the condition as it appears to set the path for / B / AM. Regardless of the xml regardless of condition

There are many errors, but as you say, you are new.

First of all, if you have the recorded file path "1" then you should come safely to xmlmenu.

The next line will generate an error, because with any other clause,

  • should be the correct instruction (bracket)
  • (< / Code> should be on the same physical line because if
  • the sequence ) and ( should be all the same physical line (which is the If not )

In any case, else is unnecessary. If condition will not jump, therefore execute next statement line Will be done Is not.

if ... == ... is true, then the string is similar to the sring on the left right, so you can change the if file: //path/of/file/*/*/*/*/A/*.XML entry will be required> Action statement to be correct Even if should be on the same physical line as , this syntax is another source of errors.

set is then executed, that Popular String (A Specify Dhrn) on the variable file path . And then we are going to do OpenXML

Note that \ is a path separator in Windows .; / is a switch-specifier.

Now - if you wanted to tell what you want to do - maybe enter a filename that can be elsewhere in any directory structure and if it is found then the variable is in the file path What? Assign one or two examples would be a good idea.


This should be going to be an usable system. Numerical checking is incomplete, but I will not have it fixed against a bullet proof user to break it ...

  off @ECHO SETLOCAL: set "filepath =" set / p filePath = "yyyymmdd filepath as set again:" if filepath defines not goto: EOF if registered "% filePath%" == "1" goto xml Menu :: test to see The data numeric set is / is whether a "filepath =% filepath%" 2 & gt; Null if% filepath% == 0 echo invalid entry - numerics only, please & amp; If goto% filepath% lss 19800,100 gotymd goto% filepath% gtr 20,991,231 goto filepath SET badymd = \ path \ prefix \% filepath: ~ 0,4% \% filepath: ~ 4,2% \% filepath: ~ 6, 2% :: This is just to show filepath ECHO filepath "% filepath%" if it does not exist "% filepath% \" is a * xml "echo"% filepath% \ an * * xml does not exist & amp; If Goto is not present then "....% filepath% \ b * * XML" echo "% filepath% \ b \ * xml" does not exist & amp; Geto re-set "filepath =% filepath% \ b \ * XML." Goto OPENXML: Badymd invalid entry echo - 4 points for the year, for a 2 day for 2 days, GO please EOF  

Obviously, change the path prefix for: EOF Goto: To redo: xmlmenu xmlmenu & amp; AT ECHO; Goto: EOF Goto filepath = OpenXML with OpenOpenXML ECHO suite with "% filepath%" & An input of

20140220 will be created for the path to .... \ 2014 \ 02 \ 20 . After this there is a check for and this + \ B * *. Xml - I can only assume that both must be present to run on openxml .


Comments