Jump to content
  • Advertisement
Sign in to follow this  
hoihoi8

Help with trying to learn bat files

This topic is 4158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, The programmer on my project quit leaving me, the AP, to make the final touches on our project, until a new programmer is hired. I'm trying to work with his "bat", which builds our games. Could anyone take a shot at doing a simple line by line translation? JSCompressCL and Compress compresses the JS files for each game. del /F /Q ..\Release\%1 mkdir ..\Release\%1 xcopy ..\%1 ..\Release\%1 /E /S /Y rem ALSO copy over the required aux files: copy ..\test\required\*.* ..\Release\%1 rem now compress all of the js files: for %%f in ( ..\%1\*.js ..\%1\*.htm) do JSCompressCL /q /k /o:..\Release\%1 %%f del /S ..\Release\%1\*.mySCMServerInfo rem del /F ..\Release\%1\game_preloader.htm rem Now generate the preloader htm file. rem cd ..\Release\%1 rem call ..\..\compress\preload_tag_writer.exe game_preloader.htm rem cd ..\..\compress

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by hoihoi8
Hello all,

The programmer on my project quit leaving me, the AP, to make the final touches on our project, until a new programmer is hired. I'm trying to work with his "bat", which builds our games. Could anyone take a shot at doing a simple line by line translation? JSCompressCL and Compress compresses the JS files for each game.

del /F /Q ..\Release\%1
mkdir ..\Release\%1
xcopy ..\%1 ..\Release\%1 /E /S /Y
rem ALSO copy over the required aux files:
copy ..\test\required\*.* ..\Release\%1

rem now compress all of the js files:
for %%f in ( ..\%1\*.js ..\%1\*.htm) do JSCompressCL /q /k /o:..\Release\%1 %%f


del /S ..\Release\%1\*.mySCMServerInfo
rem del /F ..\Release\%1\game_preloader.htm

rem Now generate the preloader htm file.
rem cd ..\Release\%1
rem call ..\..\compress\preload_tag_writer.exe game_preloader.htm
rem cd ..\..\compress


I'll try to help with a bit of it.

Firstly, when you type batchfilename something, any occurance of %1 in the batchfile will be replaced by something, so the above file is designed to be run with a parameter (a directory name by the look of it) and all the %1's will be replaced by whatever name you provide.

You're probably aware that .. in paths means "go up one directory", so ..\Release\ means "a directory called Release in the directory above the one we're in".

So if you are in C:\Abc\Def, and type batchfilename arglebargle, then ..\Release\%1 would translate to C:\Abc\Release\arglebargle.

Any line starting rem is a comment and is ignored so we can forget those.

del /F /Q ..\Release\%1
Delete the directory specified by the system described above based on the parameter specified

mkdir ..\Release\%1
Recreate an empty directory with the same name and location as the one just deleted. I'll refer to this directory as "Destination" for now (see below).

xcopy ..\%1 ..\Release\%1 /E /S /Y
This assumes that in the same directory as Release, there is a directory with the same name as the one we just deleted and recreated. I'll refer to this directory as "Source" for now (see below). Copy everything in this directory into "Destination".

copy ..\test\required\*.* ..\Release\%1
From the directory one up from where we are, in a directory called test then in a subdirectory called required, copy every file into "Destination".

for %%f in ( ..\%1\*.js ..\%1\*.htm) do JSCompressCL /q /k /o:..\Release\%1 %%f
For each file in "Source", apply the JSCompressCL program to each file and output the result into "Destination".

del /S ..\Release\%1\*.mySCMServerInfo
Delete any files with the extensino mySCMServerInfo from "Destination".

The remaining lines have been commented out for some reason so will be ignored, but it looks as though they once did something. To re-enable them, just delete the word "rem" from the start of each line.

rem del /F ..\Release\%1\game_preloader.htm
Delete the file game_preloader.htm from "Destination"

rem cd ..\Release\%1
Move into the "Destination" directory

rem call ..\..\compress\preload_tag_writer.exe game_preloader.htm
Runs the program preload_tag_writer.exe passing game_preloader.htm as an argument. Since we just deleted game_preloader.htm, I'd assume that preload_tag_writer.exe generates a new version.

rem cd ..\..\compress
This runs the compress program, which I assume applies itself to every file in the current directory, although you probably have a better idea than I do.

This has taken ages to type, so several other people have probably already posted better explanations than this by the time I've finished [smile].

Hope it helps, anyway.

Share this post


Link to post
Share on other sites
Edit: Beaten to it! [smile]

Hi!


del /F /Q ..\Release\%1


del means to delete files. The /F switch forces the deletion of read-only files and /Q runs the deletion in quiet mode, meaning you won't get asked for confirmation of deleting the files. The ..\Release\%1 portion is the directory to delete files from. First it goes up a directory with ..\, then into the Release\%1 directory, where %1 is a parameter that's been added after the batch filename. For example, if you wrote a batch file called greetme with the following contents:


echo Hello %1


and then ran the script from the command prompt like so:


greetme John


it would output Hello John to the screen.


mkdir ..\Release\%1


mkdir is short for "make directory", thus it makes the directory ..\Release\%1


xcopy ..\%1 ..\Release\%1 /E /S /Y


The xcopy command copies files and directory trees. The first parameter, ..\%1, is the directory to copy files from. The second, ..\Release\%1, is the directory to copy the files to. The switch /E copies all directories and subdirectories including empty ones.
The switch /S copies all directories and subdirectories, excluding empty ones.
The switch /Y is similar to the quiet mode switch for del in that it supresses prompting to confirm if you want to overwrite an existing files.


rem ALSO copy over the required aux files:
copy ..\test\required\*.* ..\Release\%1


Any line starting with the word rem is obviously a comment. copy copies files to another directory. As with xcopy, the first 2 parameters are the source and destination directories. The *.* represents all files (so basically all files in the ..\test\required directory are copied to the ..\Release\%1 directory).


rem now compress all of the js files:
for %%f in ( ..\%1\*.js ..\%1\*.htm) do JSCompressCL /q /k /o:..\Release\%1 %%f


I'll be honest, I'm really not sure what this is doing, but at a guess, I'd imagine for is a looping construct just like with any other programming language, and that it's looping through every .js and .htm file (I'm presuming %%f is the file/filename) in the ..\%1\ directory, compressing them to ..\Release\%1, using the same filename (%%f).


del /S ..\Release\%1\*.mySCMServerInfo


The /S switch for the del command deletes specified files from all directories, in this case *.mySCMServerInfo files are deleted from ..\Release\%1\.


rem del /F ..\Release\%1\game_preloader.htm

rem Now generate the preloader htm file.
rem cd ..\Release\%1
rem call ..\..\compress\preload_tag_writer.exe game_preloader.htm
rem cd ..\..\compress


The rest of these are all commented out but the first one would delete the game_preloader.htm file, even if it was read-only, from the ..\Release\%1\ directory. cd is short for "change directory", so cd ..\Release\%1 would change to the ..\Release\%1\ directory. Again I'm not certain of this one, but call apparently calls another batch file from this one. So I'm guessing the call command here invokes the preload_tag_writer.exe batch file in the ..\..\compress\ directory, passing game_preloader.htm as an argument.
Then cd ..\..\compress changes to the ..\..\compress directory.

I'm a bit rusty with batch files but I hope this is of some use to you. If anyone spots any mistakes, feel free to let me know.

Hope that helps. [smile]

Share this post


Link to post
Share on other sites
EasilyConfused,

In the last line of the file you'd have to remove the cd in order for it to invoke the ..\..\compress program, I believe. A test confirmed that for me here anyway. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by John H
EasilyConfused,

In the last line of the file you'd have to remove the cd in order for it to invoke the ..\..\compress program, I believe. A test confirmed that for me here anyway. [smile]


Oops. Yep. Well spotted. That last line would move you into the ..\..\compress folder, not run a program called compress.

Doh! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!