Page 1 of 1

Script checking for last line text (recursive)

Posted: 18 Dec 2016 09:26
by bufoss
Hi all,
I an noobie in batch scripting and I would appreciate if you could help me.

I want to create a script which reads a root path (windows path or svn path),
checking only the .sql files which are inside "Packages" and "Package Bodies" folders.
The script I would like to check if the last line of the .sql file is "/".

When the script changes folder print *******

Could you help me please ?
Thanks in advance

Code: Select all

@echo off&cls

setlocal enabledelayedexpansion

set initialPath=%~dp0
set /p rootPath=Path :

cd %rootPath%

for %%a in (*.sql) do (
    for /f "delims=" %%b in ('type "%%a"') do (
        set "$Line=%%b"
    )
    if not "!$Line:~-1!"=="/" (
        echo %%~nxa [!$Line:~-1!] =^> Not valid
        ) else (
        echo %%~nxa [!$Line:~-1!] =^> OK
        )
    echo.^**************
)

cd %initialPath%

:End
endlocal
pause >nul

Re: Script checking for last line text (recursive)

Posted: 21 Dec 2016 15:48
by pieh-ejdsch
this lines only with Findstring print on Screen.

Code: Select all

@echo off
setlocal disabledelayedexpansion
set prompt=$G$S
::Define LF variable containing a linefeed (0x0A)
(set ^"LF=^
%= Pseudo empty Line =%
)
::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
setlocal enableDelayedExpansion

if "%~1" == "/?" echo ON &call :help &exit /b

if :==:SUB (
:help
 rem %~0 "%~f0"

 rem Letzte Zeile mit Text ohne Zeilenschaltung ausgeben
findstr /n /v /r /c:^".*^!CR^!^!LF^!*^!CR^!*^!LF^!*^" "%~f0"

 rem Letzte Zeile mit Text mit Zeilenschaltung ausgeben
findstr /n /v /r /c:^".*^!CR^!^!LF^!.*^!CR^!^!LF^!*^!CR^!*^!LF^!*^" "%~f0"

 rem Letzte Zeile mit Inhalt mit Zeilenschaltung ausgeben.
(type "%~f0" &type nul)|findstr /n . |findstr /v /r /c:^".*^!CR^!^!LF^!.*^!CR^!^!LF^!*^!CR^!*^!LF^!*^" |findstr /r \/$ &&echo   OK
 rem
exit /b
)

call :sql "Packages" "Package Bodies"

if : equ :SUB (
:sql this ERRORmessages filter 2>nul
rem %~0
set/aFP=0
set "Pipe=>&2 "
for /r %1 %%f in (*.sql )do (
  ( type "%%f" &type nul ) | findstr /n .  | findstr /v /r /c:^".*^!CR^!^!LF^!.*^!CR^!^!LF^!*^!CR^!*^!LF^!*^"  | findstr /r \/$  && (
    echo %%~nxf      / =^> OK
    set "pipe="
  ) || @ >&2 (echo %%~nxf =^> Not valid
  )
  if "%%~dpf" neq "!FP!" @ %PIPE% (
    echo **************
    echo       "%%~dpf"
    set "FP=%%~dpf"
    set "Pipe=>&2 "
  )
)
if "%~2" neq "" shift & goto :sql
exit /b
)

rem END Script
Exit /b

Testlines
/abcde
xyz / End
000/
/abc
/xyz
22/2
999/


Phil

Re: Script checking for last line text (recursive)

Posted: 02 Jan 2017 11:56
by bufoss
Thanks a lot for your help