Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / can anyone help with a simple Windows batch file?

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Sep 2014 00:31
I'm trying to write a simple .bat file which will compile a series of input shader .fx files and write the compiled output files as .obj files. The bat file works except for one thing: I can't see how to add the extension .obj to the output file names. For example an input file "myShader.fx" gets compiled and saved as "myShader".

Here's what I have so far (I'm using the DirectX shader compiler fxc.exe):



If I use the compiler for a single file then the following does what I want:



I was hoping to use simple string manipulations on the string %%X in the for/do loop to produce the desired output name but can't seem to get it to work as desired.

It's been over 25 years since I last wrote a .bat file so I'm a bit rusty - and I guess a few things have changed since then .

Any suggestions?



Powered by Free Banners
TheComet
16
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 22nd Sep 2014 01:18
You can get a substring of var with the syntax %var:~from,length%, and interestingly if you supply a negative value for length it truncates the characters at the end of the string.

Since in your case the length of the extension is known, something like this should do it:



...or something like that. I'm running linux so can't test, sorry.

I like offending people. People who get offended should be offended. -- Linux Torvalds
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Sep 2014 01:29
Thanks. That was what I tried first and couldn't get to work. However, I did find something similar that works:



It seems that I had to remove the extender first, i.e. %%~nX then add it in again as the main argument to fxc, i.e. %%~nX.fx, and then do the same for the output file name, i.e. %%~nX.obj. Works nicely.

For anyone else interested, here's the relevant MS documentation which told me what to do:

Use of For command in batch files

Ah! Memories ...



Powered by Free Banners

Login to post a reply

Server time is: 2024-03-28 21:23:56
Your offset time is: 2024-03-28 21:23:56