Raised This Month: $32 Target: $400
 8% 

[.BAT file] Compile entire folders!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-02-2021 , 20:43   [.BAT file] Compile entire folders!
Reply With Quote #1

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
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-03-2021 , 06:08   Re: [.BAT file] Compile entire folders!
Reply With Quote #2

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
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:15.


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