Page 1 of 1

Post your most advanced script

Posted: 25 Oct 2011 18:58
by Rileyh
Hi everyone,
Out of interest, I would like to make this post to see what an ultra-advanced batch script would look like.
A definition of "ultra-advanced" would be "the most versatile". It should be able to "do the most things".
So post your script as a reply to this post and lets see who has the most versatile script in DosTips!

Re: Post your most advanced script

Posted: 25 Oct 2011 21:35
by Ed Dyreen
Is this advanced :?:

Code: Select all

::--------------------------------------------------------------------------------------------------------------------------
goto :skip "()"
::
:§Declare.RegKeyObject ()
::
rem %_forT% ( "!$Trace!" ) %@Debug.on%
::
%_forP% ( '"#Name,""%%~a""", "Path,""%%~b""", "#Key,""%%~c""", "Data,""%%~d"",#", "Type,""%%~e"",#", "#SetsError,""%%~f"",0"' ) %@Param%
::(
   %_necho% !$Trace!: '!$Name!'
   %@sLError% &%@rError% &(
      %_forX% ( '"!$Name!", "!$Path!"' ) %@Declare.RegPathLHE% &%@gLError%
      %_forX% ( '"!$Name!", "!$Type!"' ) %@Declare.RegTypeLHE% &%@gLError%
   ) &%@sLError%
   ::
   if !$error! equ 0 (
      ::
      set "$Return=$error"
      set "!$Name!.0=RegKey"
      set "!$Name!.Key=!$Key!"
      set "!$Name!.Data=!$Data!"
      set "!$Name!.method=exist, write, read, delete, touch"
      %_forX% ( '"!$Name!", 1' ) %@Declared.ObjectL%
   ) else    %@IfSetsErrorExit%

%   % set ^"%$Declared%.exist=!@Udelim! ( %$n1c%
%      % !_forT! ( "%$Declared%.exist" ) !@SetLocal! %$n1c%
%      % !_forL! ( '"#SetsError,""%%~a"",0"' ) !@Param! %$n1c%
%      % !_necho! ^^^!$Trace^^^!: '^^^!%$Declared%.Key^^^!' %$n1c%

%      % !_necho!  $Path: '^^^!%$Declared%.Path^^^!' %$n1c%
%      % if not defined $Key ( %$n1c%
%      %    !_tError! 2 %=               $2.error=input missing=% %$n1c%
%      % ) else ^>nul 2^>^&1 reg query "^!%$Declared%.Path^!" /v "^!%$Declared%.Key^!" ^|^|( %$n1c%
%      %    !_tError! 17 %=             $17.error=Object not physically exists=% %$n1c%
%      % ) %$n1c%
%      % !@IfSetsErrorExit! %$n1c%

%      % !_forL! ( '^^^!$Return^^^!' ) !@EndLocal! ^&!@nError! %$n1c%
%   % ) ^&if ^^^!$error^^^! EQU 0 ^>nul echo.chain"
   ::
   ::set "$obj.exist=!%$Declared%.exist!"
   ::%_forX% ( '0' ) %$obj.exist% ||(%@endoftest%)

%   % set ^"%$Declared%.write=!@Udelim! ( %$n1c%
%      % !_forT! ( "%$Declared%.write" ) !@SetLocal! %$n1c%
%      % !_forL! ( '"#SetsError,""%%~a"",0"' ) !@Param! %$n1c%
%      % !_necho! ^^^!$Trace^^^! %$n1c%

%      % !_necho!  $Path: '^^^!%$Declared%.Path^^^!' %$n1c%
%      % !_necho!  $Key : '^^^!%$Declared%.Key^^^!' %$n1c%
%      % !_necho!  $Type: '^^^!%$Declared%.type^^^!' %$n1c%
%      % !_necho!  $Data: '^^^!%$Declared%.Data^^^!' %$n1c%
%      % set "$Data=^!%$Declared%.Data:""=\"^^^!^^^" %$n1c%
%      % ^>nul reg add "^!%$Declared%.Path^!" /v "^!%$Declared%.Key^!" /t ^^^!%$Declared%.type^^^! /f /d "^!$Data^!" ^|^|!@gError! %$n1c%
%      % !@IfSetsErrorExit! %$n1c%

%      % !_forL! ( '^^^!$Return^^^!' ) !@EndLocal! ^&!@nError! %$n1c%
%   % ) ^&if ^^^!$error^^^! EQU 0 ^>nul echo.chain"
   ::
   ::set "$obj.write=!%$Declared%.write!"
   ::%_forX% ( '1' ) %$obj.write% ||(%@endoftest%)

%   % set ^"%$Declared%.read=!@Udelim! ( %$n1c%
%      % !_forT! ( "%$Declared%.read" ) !@SetLocal! %$n1c%
%      % !_forL! ( '"#SetsError,""%%~a"",0"' ) !@Param! %$n1c%
%      % !_necho! ^^^!$Trace^^^! %$n1c%

%      % !_necho!  $Path: '^^^!%$Declared%.Path^^^!' %$n1c%
%      % !_necho!  $Key : '^^^!%$Declared%.Key^^^!' %$n1c%
%      % ^>nul 2^>^&1 reg query "^!%$Declared%.Path^!" /v "^!%$Declared%.Key^!" ^&^&( %$n1c%

%      %    for /f "skip=4 tokens=2,3* delims=   " %%r in ( %$n1c%

%      %       '2%e5%>nul reg query "^!%$Declared%.Path^!" /v "^!%$Declared%.Key^!"' %$n1c%

%      %    ) do ( %$n1c%

%      %       set "%$Declared%.type=%%r" %$n1c%
%      %       set "%$Declared%.data=%%s" %$n1c%
%      %       if not defined %$Declared%.data if ^^^!$SetsError^^^! neq 0 ( %= $4.error=variable undefined =% %$n1c%
%      %          !_tError! 4 %$n1c%
%      %       ) else    !_tError!-4 %$n1c%

%      %    ) %$n1c%
%      % ) ^|^|!_tError! 17 %=               $17.error=Object not physically exists=% %$n1c%
%      % !@IfSetsErrorExit! %$n1c%
%      % !_necho!  $Data: '^^^!%$Declared%.Data^^^!' %$n1c%
%      % !_necho!  $Type: '^^^!%$Declared%.type^^^!' %$n1c%
%      % set "%$Declared%=^!$Data^!" %$n1c%

%      % !_forL! ( '^^^!$Return^^^!, %$Declared%, %$Declared%.type, %$Declared%.data' ) !@EndLocal! ^&!@nError! %$n1c%
%   % ) ^&if ^^^!$error^^^! EQU 0 ^>nul echo.chain"
   ::
   ::set "$obj.read=!%$Declared%.read!"
   ::%_forX% ( '0' ) %$obj.read% ||(%@endoftest%)

%   % set ^"%$Declared%.delete=!@Udelim! ( %$n1c%
%      % !_forT! ( "%$Declared%.delete" ) !@SetLocal! %$n1c%
%      % !_forL! ( '"#SetsError,""%%~a"",0"' ) !@Param! %$n1c%
%      % !_necho! ^^^!$Trace^^^!: '^^^!%$Declared%.key^^^!' %$n1c%

%      % !_necho!  $Path: '^^^!%$Declared%.path^^^!' %$n1c%
%      % ^>nul ( %$n1c%
%      %    2^>nul reg query "^!%$Declared%.path^!" /v "^^^!%$Declared%.key^^^!" ^&^&( %$n1c%
%      %       reg delete "^!%$Declared%.path^!" /v "^^^!%$Declared%.key^^^!" /f ^|^|( %$n1c%
%      %           !_tError! 20 %=            $20.error=object delete failed=% %$n1c%
%      %       ) %$n1c%
%      %    ) %$n1c%
%      % ) %$n1c%
%      % !@IfSetsErrorExit! %$n1c%

%      % !_forL! ( '^^^!$Return^^^!' ) !@EndLocal! ^&!@nError! %$n1c%
%   % ) ^&if ^^^!$error^^^! EQU 0 ^>nul echo.chain"
   ::
   ::set "$obj.delete=!%$Declared%.delete!"
   ::%_forX% ( '0' ) %$obj.delete% ||(%@endoftest%)

%   % set ^"%$Declared%.touch=!@Udelim! ( %$n1c%
%      % !_forT! ( "%$Declared%.touch" ) !@SetLocal! %$n1c%
%      % !_forL! ( '"#SetsError,""%%~a"",0"' ) !@Param! %$n1c%
%      % !_necho! ^^^!$Trace^^^!: '^^^!%$Declared%.key^^^!' %%~b %$n1c%

%      % !_necho!  $Path: '^^^!%$Declared%.Path^^^!' %$n1c%
%      % if /i ["%%~b"] == ["Destroy"] ( %$n1c%
%      %    !_forX! ( '"^!%$Declared%.path^!", "^!%$Declared%.key^!", "^!%$Declared%.data^!", "^!%$Declared%.type^!", ^^^!$SetsError^^^!' ) !@RegWriteKeyLHE! %$n1c%
%      % ) else ( %$n1c%
%      %    !_forX! ( '"%$Declared%", "^!%$Declared%.path^!", "^!%$Declared%.key^!", ^^^!$SetsError^^^!' ) !@RegReadKeyLHE! %$n1c%
%      %    set "%$Declared%.type=^!$type^!" %$n1c%
%      %    set "%$Declared%.data=^!$data^!" %$n1c%
%      % ) %$n1c%
%      % !@IfSetsErrorExit! %$n1c%
%      % !_necho!  $Type: '^^^!%$Declared%.type^^^!' %$n1c%
%      % !_necho!  $Data: '^^^!%$Declared%.data^^^!' %$n1c%

%      % !_forL! ( '^^^!$Return^^^!, %$Declared%.type, %$Declared%.data' ) !@EndLocal! ^&!@nError! %$n1c%
%   % ) ^&if ^^^!$error^^^! EQU 0 ^>nul echo.chain"
   ::
   ::set "$obj.touch=!%$Declared%.touch!"
   ::%_forX% ( '1, Destroy' ) %$obj.touch% ||(%@endoftest%)

   %_forT% ( !%$Declared%.method! ) do set "$returnAdvanced=!$returnAdvanced!, !$Declared!.%%~!"
::)
%@nError% &exit /b %$error%
::--------------------------------------------------------------------------------------------------------------------------
::
goto :skip "()"
%@endoftest%
:skip ()

Code: Select all

 >> Pre Define @Declare.FileObject, [Re]Create a File
 << Post Define @Declare.FileObject, [Re]Create a File [OK]

 º@Declare.FileObject: '$aFile'
 @Declared.ObjectL: '$aFile'
  $aFile: 'C:\This Works.TMP'
  $0: 'File'
  $FullPathFile: 'C:\This Works.TMP'
  $FullPath: 'C:'
  $Path: 'C:'
  $Drive: 'C:'
  $File: 'This Works.TMP'
  $FileName: 'This Works'
  $FileExtension: 'TMP'
  $method: 'exist, delete, touch, move'
 [ok:0]
 [ok:0]

 $aFile.exist: 'C:\This Works.TMP'
 [error:17] Object not physically exists !
 endoftest Druk op een toets om door te gaan. . .
STOP a 400 kb script don't fit :lol:

Anyways, are u here to learn DOS or are u looking for a library that u can reuse in every DOS app, there are multiple libraries available, I am currently writing this one but it's an experimental one, I'm working on getting it more practical, bugfree and logical ...

I just noticed the path schouldn't be $path 'C:' but '' :oops:
O my dog, it's full with bugs, I just wrote this, implementing methods, because they are faster than macros (after declaration), so I claim.

Re: Post your most advanced script

Posted: 26 Oct 2011 00:14
by Rileyh
Very advanced (looks even more advanced since I am a noob)
What do you mean by macro?
Could you email me the 400 kb script (email at bottom)


Great script,
Rileyh

Re: Post your most advanced script

Posted: 26 Oct 2011 02:28
by Ed Dyreen
'
Macro (computer science)
From Wikipedia, the free encyclopedia

A macro (from the Greek μακρό for "big" or "far") in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure. The mapping process that instantiates (transforms) a macro into a specific output sequence is known as macro expansion.

The term is used to make available to the programmer, a sequence of computing instructions as a single program statement, making the programming task less tedious and less error-prone.[1][2] (Thus, they are called "macros" because a big block of code can be expanded from a small sequence of characters). Macros often allow positional or keyword parameters that dictate what the conditional assembler program generates and have been used to create entire programs or program suites according to such variables as operating system, platform or other factors.

http://en.wikipedia.org/wiki/Macro_%28c ... science%29

Code: Select all

@echo off
%= macro definition =%
set "macro=echo.This &echo.Works"
%= macro expansion =%
%macro%
pause
exit /b

Re: Post your most advanced script

Posted: 26 Oct 2011 19:35
by Rileyh
Is this good enough (it is an extremely underfunctionable operating system im developing)

Code: Select all

@echo off 
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION
title DOS 7

:.
echo ===============Welcome to DOS 7.===============
timeout /t 2 /nobreak >nul
set /p a=If this is your first time using DOS 7, press 1. If not, press 2. What do you want to do?:
if /i _"%a%"==_"1" (goto :2) else goto :3

:2
echo Thank you for choosing DOS 7. You need to set up your account now.
timeout /t 1 /nobreak >nul
set /p user= Enter your desired username. This is what will show up when you log in.Username:
echo Configuring....
timeout /t 1 /nobreak >nul
set "1=%user%
set /p pass= Please enter your desired password. This will be the security key that you type in to log in. Password:
echo Configuring....
timeout /t 1 /nobreak >nul

:dir
echo Please choose which drive you would like to make your account in. This is where your files will be stored. Drive: (type the exact drive with ":\")
echo Choose a drive:
timeout /t 1 /nobreak >nul
set /a n=0
echo Number   Drive Name
for /f "tokens=2 delims==" %%i in ('wmic logicaldisk get name /value') do (
  set /a n+=1
  echo !n!        %%i
  set "d_!n!=%%i"
)
:loop
echo(
set "num="
set /p "num=Choose a number: "
if defined d_%num% (
  set "drive=!d_%num%!"
) else (
  echo This drive doesn't exist^^!
  goto :loop
)
set "drive=%drive%"
echo(
set /p config=Confirming that you have specified drive %drive%? (type Y/N):
if /i "%config%"=="Y" (md %drive%\DOS7\%user%) & if %errorlevel% 1 goto :dir2 else goto :dir
chdir /D "%drive%\DOS7"
echo found>find.txt
echo Configuring....
timeout /t 1 /nobreak >nul
echo You have now set up your account as %user%.
timeout /t 1 /nobreak >nul
echo Finalising settings....
echo %user% >%drive%\DOS7\%user%\username.txt
echo %pass% >%drive%\DOS7\%user%\password.txt
timeout /t 1 /nobreak >nul
goto :login

:dir2
echo An error occured while trying to make your account files in %dir%
pause >nul
goto :dir

:ill
echo You have either not answered, or have specified an illegal directory.
pause >nul
goto :dir

:login
cls
set "j=%drive2%"
set /p k=Enter your previous username for clarification:
echo Please log in:
set /p b=Username:
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass) else goto :con
:con
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass)
echo Incorrect Username.
pause >nul
set /p b=Username:
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass) else goto :con1
:con1
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass)
echo Incorrect Username.
pause >nul
set /p b=Username:
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass) else goto :con2
:con2
find /C /I "%b%" %j%\DOS7\%k%\username.txt
if %errorlevel%==0 (goto :pass)
echo Incorrect Username.
pause >nul
goto :lockout
:pass
set /p c=Password:
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....) else goto :con3
:con3
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....)
echo Incorrect Password.
pause >nul
set /p c=Password:
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....) else goto :con3
:con4
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....)
echo Incorrect Password.
pause >nul
set /p c=Password:
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....) else goto :con3
:con5
find /C /I "%c%" %j%\DOS7\%k%\password.txt
if %errorlevel%==0 (goto :....)
echo Incorrect Password.
pause >nul
goto :lockout
:....
echo Logging in....
timeout /t 3 /nobreak >nul
cls
goto :4

:3
echo Welcome back. DOS 7 must validate your previous account to continue login. This is only temporary, as you can continue skip this step on the next bootup.
echo Select the drive that your account is in:
set /a n=0
echo Number   Drive Name
for /f "tokens=2 delims==" %%i in ('wmic logicaldisk get name /value') do (
  set /a n+=1
  echo !n!        %%i
  set "d_!n!=%%i"
)
:loop2
echo(
set "num="
set /p "num=Select the drive that your account is in: "
if defined d_%num% (
  set "drive2=!d_%num%!"
) else (
  echo This drive doesn't exist^^!
  goto :loop2
)
set "drive2=%drive2%"
echo(
echo DOS is searching for your accout....
find /C /I "found" %drive2%\DOS7\find.txt
if %errorlevel%==0 goto :cont
if %errorlevel%==1 goto :error
goto :error
:cont
chdir /D "%drive2%"
echo Welcome back.
cls
goto :login
:error
set /p j=There has been an error in Login. You must wait until Riley makes a troubleshooter script, press "4" to retry at a different directory or "W" to exit to Windows. What do you want to do:
if /i _"%j%"==_"W" (goto :w)
if /i _"%j%"==_"4" (goto :redo)
pause >nul
goto :eof

:4
goto :menu
echo Loading....
timeout /t 1 /nobreak >nul
echo  -Running config files....
timeout /t 1 /nobreak >nul
echo  -Preparing desktop...
timeout /t 1 /nobreak >nul
echo  -Compiling desktop....
timeout /t 1 /nobreak >nul
echo  -Compiling settings....
timeout /t 1 /nobreak >nul
echo  -Finalising software....
timeout /t 1 /nobreak >nul
echo Initialising....
timeout /t 1 /nobreak >nul
echo Welcome.
:menu
timeout /t 1 /nobreak >nul
echo      ______________________________________________________________               
echo      I %b%'s Account     ----DOS 7----                           I
echo      I                      Hello %b%                            I
echo      I     Options:  - L = List all files in your directory        I
echo      I               - N = Makes a new text document to edit       I
echo      I               - B = Makes a new batch file to edit          I
echo      I               - R = Returns to this menu                    I
echo      I               - W = Exits to windows                        I
:taskpoint
set "emptytaskspace=-%name% = %prompt%"
echo      I               %EMPTYTASKSPACE%                                              I
echo      I                                                             I
echo      I   You can alternatively make a new task by pressing T.      I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I                                                             I
echo      I___________________________________________                  I
set /p e="IWhat do you want to do? (Type in Lowercase)I_________________  I
if /i _"%e%"==_"l" (call :l)
if /i _"%e%"==_"n" (call :n)
if /i _"%e%"==_"b" (call :b)
if /i _"%e%"==_"r" (call :r)
if /i _"%e%"==_"w" (call :w)
if /i _"%e%"==_"t" (call :t)
goto :menu

:l
tree %j%\DOS7\%b%
pause >nul
goto :menu

:n
chdir /D %j%\DOS7\%b%
set /p name= What do you want to call the file?
find /c %name%
if %errorlevel%==1 goto :exist
edit %name%.txt
goto :menu

:exist
echo Filename already exists.
set /p ren= New name :
set /p f= Are you sure you want to rename this file (press Y/N)
if /i _"%f%"==_"Y" (echo OK &pause) else goto :exist
ren %name%.txt %ren%.txt
goto :menu

:b
chdir /D %j%\DOS7\%b%
set /p name= What do you want to call the file?
find /C /I "%name%"
if %errorlevel% 0 goto :exist
edit %name%.bat
goto :menu

:r
goto :menu

:w
set /p g= Are you sure you want to exit to Windows? (press Y/N)
if /i _"%g%"==_"Y" (exit /b 1) else goto :no

:no
goto :menu

:t
set "n=0"
goto :new
:tcont
echo There is currently %n% spaces left for new tasks.
set /p l= Do you want to make a new task? (Y/N)
if /i _"%l%"==_"y" (goto :ncont) else goto :menu
:new
set "n-=1"
goto :tcont
:ncont
set /p name= What do you want to make the prompt key be? (Type a letter) (Type a name)
set /p prompt= Type a task description :
goto :taskpoint
pause >nul


In my opinion it is pretty good because im a noob.

Rileyh

Re: Post your most advanced script

Posted: 26 Oct 2011 22:05
by Ed Dyreen
'
Here is the link to my old library, it's ONLY for educational purpose !
In the code you will find all tricks and methods I use to accomplish tasks.

I am currently working on a new version that supports methods on objects and is a lot faster &stable. I will post the update on this same page when the library is more mature.

viewtopic.php?f=3&t=1893&start=0&hilit=my%2Four+contribution

you will encounter constructions like this in the code:

Code: Select all

::
goto :skip
%@endoftest%
:skip ()
To pause and play with the above code, change it to:

Code: Select all

::goto :skip
%@endoftest%
:skip ()