Thomas Williams
Thomas Williams

Reputation: 1548

batch file not working in windows 10 upgrade

I have a batch file which runs ajaxMinfier and compresses my css and jquery. My xml files use relative paths. Now everything worked in windows 7, but recently I upgraded to windows 10 and now my batch files are failing. What happens is if I double click my batch file it fails to find my xml files in the same folder.

I have them like this

compress.bat
css.xml
jquery.xml

I always give the full path to ajaxMinifier in the batch file and that is fine. It is running, but give relative paths to my files in my xml. The reason being is that I have multiple copys of webpages at different stages.

If I go in using command line and run my batch file everything works, but of course I am in the folder that I am running the batch file from. If I click on my batch file in windows, it can't even find my xml files which are in the same location as my batch file.

I put a pause at the end, and I suspect the reason is that it is looking for my xml files in C: rather than the location of the batch file.

Here is my batch file

::Work
E:\Utilities\AjaxMinifier\AjaxMinifier.exe -JS -CLOBBER -xml jquery.xml
E:\Utilities\AjaxMinifier\AjaxMinifier.exe -CSS -CLOBBER -xml css.xml


pause > nul

The pause is usually commented out, but I need to see what is going on.

and here is my css xml file

<root>
<output path="..\httpdocs\css\min\my.css">
    <input path="..\httpdocs\css\raw\buttons.css"/>
    <input path="..\httpdocs\css\raw\menustyles.css"/>
  </output>
</root>

and my jquery xml file

<root>
  <output  path="../httpdocs\js\min\mutual.js">
    <input path="../httpdocs\js\raw\table_scroll.js"/>
    <input path="../httpdocs\js\raw\mutual.js"/>
    <input path="../httpdocs\js\raw\menudrop\menu_jquery.js"/>
  </output>
</root>

Can anybody tell me how make it load in the xml files in the same folder by double clicking on the batch file? I can't use fixed paths.

Upvotes: 0

Views: 3309

Answers (2)

Stephan
Stephan

Reputation: 56218

cd /d %~dp0 to change the working directory to the folder where your batchfile resides. (when you doubleclick your batchfile, it's working directory is %windir%\system32)

Upvotes: 2

Thomas Williams
Thomas Williams

Reputation: 1548

Thank you Stephan. I would have upvoted you but you haven't got an arrow next to your comment. So I couldn't. Not sure if you have added a comment rather than an answer. However if you answer correctly I will upvote you as you gave the best answer.

Your answer didn't work on it's own, but it lead me to the correct answer. The line you added was correct, but it needed another line to work.

setlocal
cd /d %~dp0

Upvotes: 0

Related Questions