AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [.BAT file] Compile entire folders! (https://forums.alliedmods.net/showthread.php?t=331703)

eyal282 04-02-2021 20:43

[.BAT file] Compile entire folders!
 
After all instructions you may drag'n'drop the folder into the new file, and all folders inside the folder shall be compiled as well.
Create a new file named "folder_compiler.bat", then edit it and put this code in:

Code:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
if [%1]==[] goto nofolder

set MyPath="%CD%"
cd !MyPath!

:loop
For /R %1 %%G IN (*.sp) do (
spcomp %%G
set RelativePath=%%~dG%%~pG

call:ReplaceText "!RelativePath!" !MyPath! "" RESULT
Set RESULT=!RESULT:~1!
Set RESULT=!RESULT:~0,-1!

set RelativePath=!RESULT!

REM Remove quotes.
set MyPath=!MyPath:"=!

IF not exist !MyPath!\compiled\!RelativePath! md !MyPath!\compiled\!RelativePath!
move !MyPath!\%%~nG.smx !MyPath!\compiled\!RelativePath!
)
shift
if not [%1]==[] goto loop

Echo finish.

pause

goto eof

:nofolder

Echo No folder was fed to the batch file.

pause

:FUNCTIONS
@REM FUNCTIONS AREA
GOTO:EOF
EXIT /B

:ReplaceText
::Replace Text In String
::USE:
:: CALL:ReplaceText "!OrginalText!" OldWordToReplace NewWordToUse  Result
::Example
::SET "MYTEXT=jump over the chair"
::  echo !MYTEXT!
::  call:ReplaceText "!MYTEXT!" chair table RESULT
::  echo !RESULT!
::
:: Remember to use the "! on the input text, but NOT on the Output text.
:: The Following is Wrong: "!MYTEXT!" !chair! !table! !RESULT!
:: ^^Because it has a ! around the chair table and RESULT
:: Remember to add quotes "" around the MYTEXT Variable when calling.
:: If you don't add quotes, it won't treat it as a single string
::
set "OrginalText=%~1"
set "OldWord=%~2"
set "NewWord=%~3"
call set OrginalText=%%OrginalText:!OldWord!=!NewWord!%%
SET %4=!OrginalText!
GOTO:EOF


eyal282 04-03-2021 06:08

Re: [.BAT file] Compile entire folders!
 
Made it more user friendly. Still no clue how to make it show compile duration. Feel free to help.
Code:


@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

set MyPath="%CD%"
cd !MyPath!

if [%1]==[] goto nofolder

if not exist spcomp.exe goto nospcomp

:loop
For /R %1 %%G IN (*.sp) do (

spcomp %%G

set RelativePath=%%~dG%%~pG

call:ReplaceText "!RelativePath!" !MyPath! "" RESULT
Set RESULT=!RESULT:~1!
Set RESULT=!RESULT:~0,-1!

set RelativePath=!RESULT!

REM Remove quotes.
set MyPath=!MyPath:"=!

if not exist !MyPath!\compiled\!RelativePath! md !MyPath!\compiled\!RelativePath!
move !MyPath!\%%~nG.smx !MyPath!\compiled\!RelativePath! >nul 2>nul


echo.
)

shift
if not [%1]==[] goto loop

echo Press enter to exit
pause >nul
exit

goto eof

:nofolder

echo Error: No folder was fed to this file
echo.
echo Please Drag and Drop a folder to this file in order to compile the files inside it.
echo.
echo Press enter to exit
pause >nul
exit

:nospcomp

echo Error: spcomp.exe was not found in the same folder as this file.
echo.
echo Press enter to exit
pause >nul
exit

:FUNCTIONS
@REM FUNCTIONS AREA
GOTO:EOF
EXIT /B

:ReplaceText
::Replace Text In String
::USE:
:: CALL:ReplaceText "!OrginalText!" OldWordToReplace NewWordToUse  Result
::Example
::SET "MYTEXT=jump over the chair"
::  echo !MYTEXT!
::  call:ReplaceText "!MYTEXT!" chair table RESULT
::  echo !RESULT!
::
:: Remember to use the "! on the input text, but NOT on the Output text.
:: The Following is Wrong: "!MYTEXT!" !chair! !table! !RESULT!
:: ^^Because it has a ! around the chair table and RESULT
:: Remember to add quotes "" around the MYTEXT Variable when calling.
:: If you don't add quotes, it won't treat it as a single string
::
set "OrginalText=%~1"
set "OldWord=%~2"
set "NewWord=%~3"
call set OrginalText=%%OrginalText:!OldWord!=!NewWord!%%
SET %4=!OrginalText!
GOTO:EOF



All times are GMT -4. The time now is 23:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.