onlyforbopi
1/4/2017 - 8:49 PM

DOS_WRAPPER_FUNC

DOS_WRAPPER_FUNC

REM SCRIPT START
REM PRINT BASIC SCRIPT PARAMETERS
ECHO ###################################################
ECHO SCRIPT: %me% 
ECHO EXECUTION DATE : %stamp%
ECHO PARENT DIRECTORY : %parent%
ECHO.
ECHO WINRAR ON FILE : %dirfull%
ECHO DESTINATION FILE : %targetdir%
ECHO NOTIFICATION MAIL DIRECTORY : %maildir%
ECHO.
ECHO UPDATING RUN LOG : %LOGFILE%
ECHO %me% ran at %stamp% >> %LOGFILE%
ECHO.
: SUCCESFUL EXECUTION 
:: IF ANY ERROR DINGS - IT WONT GET HERE
ECHO.
ECHO SUCCESSFUL SCRIPT EXECUTION
CALL:notify10 "256" "Successful Script Execution"
ECHO.

GOTO SUCCESSNOTIFYMAIL
::::
REM PAUSE
::





:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ERROR HANDLING AREA

:error10
SETLOCAL
SET Line=%~1
SET Msg=%2
ECHO.
ECHO ATTENTION : FATAL ERROR : %Msg% ON LINE %Line%
ECHO TERMINATING SCRIPT
echo X=MsgBox( %Msg% ,0+16,"FATAL ERROR ON LINE %Line%") >msg.vbs
wscript msg.vbs
echo %Msg% ::::: Line : %Line% > %LASTRUNLOG%
GOTO ERRORNOTIFYMAIL


:warning10
SETLOCAL
SET Line=%~1
SET Msg=%2
ECHO %Msg%
echo X=MsgBox( %Msg% ,0+48,"WARNING ON LINE %Line%") >msg.vbs
wscript msg.vbs
EXIT /b

:notify10
SETLOCAL
SET Line=%~1
SET Msg=%2
ECHO %Msg%
echo X=MsgBox( %Msg% ,0+64,"NOTIFICATION ON LINE %Line%") >msg.vbs
wscript msg.vbs
EXIT /b


:: Two ways, either create it on the spot and call it in a function : ie
:error10
SETLOCAL
SET Line=%~1
SET Msg=%2
ECHO.
ECHO ATTENTION : FATAL ERROR : %Msg% ON LINE %Line%
ECHO TERMINATING SCRIPT
echo X=MsgBox( %Msg% ,0+16,"FATAL ERROR ON LINE %Line%") >msg.vbs
wscript msg.vbs
DEL msg.vbs
EXIT /b

call :error10 "20" "%Build%"


::::::::::::::::::::::::::::::::::::::::::::::::::::
:: OR CREATE A VBS AND CALL IT 

::VBS :

Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText

:: call as : 

cscript %MSGBOX% "%Build%"
wscript %MSGBOX% "%Build%"

:INITIALIZE THE DATE
::
::
:: FOR LOO = parses date time from wmic
FOR /f "delims=" %%a IN ('wmic OS Get localdatetime  ^| find "."') DO SET dt=%%a

:: STRING SLICING TO GET THE DATA
SET YYYY=%dt:~0,4%
SET YY=%YYYY:~2,2%
SET MM=%dt:~4,2%
SET DD=%dt:~6,2%
SET HH=%dt:~8,2%
SET Min=%dt:~10,2%
SET Sec=%dt:~12,2%

:: ASSIGN TO FINAL VARS
SET stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
SET mydate=%YY%%MM%%DD%



::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::DATE
::Example
@echo off 
echo %DATE%
::Output
Mon 12/28/2015

::TIME.
::Example
@echo off 
echo %TIME%
::Output
22:06:52.87

::Following are some implementations which can be used to get the date and time in different formats.
::Date in Format Year-Month-Day
::Example
@echo off 
echo/Today is: %year%-%month%-%day% 
goto :EOF 
setlocal ENABLEEXTENSIONS 
set t = 2&if "%date%z" LSS "A" set t = 1 

for /f "skip = 1 tokens = 2-4 delims = (-)" %%a in ('echo/^|date') do ( 
   for /f "tokens = %t%-4 delims = .-/ " %%d in ('date/t') do ( 
      set %%a = %%d&set %%b = %%e&set %%c = %%f)) 
endlocal&set %1 = %yy%&set %2 = %mm%&set %3 = %dd%&goto :EOF

:: This goes at almost the top of script
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)


:: This goes in the function section
:ColorText
echo off
echo %DEL% > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
EXIT /B

:: Call as
call :ColorText 0a "FILE EXISTS!"

::0 = Background color
::a = Foreground color (here green, red is c)
1. DOS_datemanip         : DOS date manipulation
2. DOS_nameofscript      : DOS get the name of the script ran
3. DOS_script_start      : DOS start of script texts
4. DOS_notify_onscreen   : Functions for on screen notifications
5. D0S_message_boxes     : Ways to print messageboxes using VBS
6. DOS_colored_input     : Ways to print on STDOUT with color
: GET THE NAME OF THE SCRIPT
:: Stores just the name not full path
SET me=%0


::NAME OF DIRECTORY SCRIPT IS RUN
:: Stores just the directory the script is ran
SET parent=%~dp0
SET STEP=STEP1
ECHO.
ECHO %STEP%
ECHO LAUNCHING WINSCP SCRIPT FOR TRANSFER FROM C/L TO LOCAL DCONNECT\OT (*.PGP)

REM C:
REM CD \\
REM cd C:\Progra~1\WinSCP



REM CD /D is used to change drive. A normal cd can only traverse in the same drive.
cd /D C:\Program Files (x86)\WinSCP
ECHO WORKING DIR %cd%
:::::::::::::::::::::::::::::::::::::::::
:: PATHNAME MANIPULATION



@ECHO OFF
SETLOCAL
set file=C:\Users\l72rugschiri\Desktop\fs.cfg
FOR %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)


@ECHO OFF
SETLOCAL
set file="C:\Users\ l72rugschiri\Desktop\fs.cfg"
FOR /F "delims=" %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)



::::::::::::::::::::::::::::::::::::::::::
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@Echo Off
Echo Directory = %~dp0
Echo Object Name With Quotations=%0
Echo Object Name Without Quotes=%~0
Echo Bat File Drive = %~d0
Echo Full File Name = %~n0%~x0
Echo File Name Without Extension = %~n0
Echo File Extension = %~x0
Pause>Nul
Output:

Directory = D:\Users\Thejordster135\Desktop\Code\BAT\

Object Name With Quotations="D:\Users\Thejordster135\Desktop\Code\BAT\Path_V2.bat"

Object Name Without Quotes=D:\Users\Thejordster135\Desktop\Code\BAT\Path_V2.bat

Bat File Drive = D:

Full File Name = Path.bat

File Name Without Extension = Path

File Extension = .bat

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::if you want infos from the actual running batchfile, try this

@echo off
set myNameFull=%0
echo myNameFull     %myNameFull%
set myNameShort=%~n0
echo myNameShort    %myNameShort%
set myNameLong=%~nx0
echo myNameLong     %myNameLong%
set myPath=%~dp0
echo myPath         %myPath%
set myLogfileWpath=%myPath%%myNameShort%.log
echo myLogfileWpath %myLogfileWpath%