Windows batch & VB Script: generate csv files by bas files and report procedures name

Luis Diaz
Luis Diaz used Ask the Experts™
on
Hello experts,
I have the following modules attached which I used in my personal Add-in.
I have a mapping table to follow up the various sub procedures.
I would like to set up a script in order to.
Generate a csv by .bas in a yyyyymmdd_hhmm folder and report in column A the sub procedure name and in column B the name of .bas file name information should be reported in ascending order
I attached .bas files.
Example:
Sub procedure name 1;Bas name
Sub procedure name 2;Bas name
Sub procedure name 3;Bas name

If you have questions, please contact me.
g2bRangesFormulas.bas
g1aStringsFormulas.bas
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
I'll assume you want the BAS files processed in name sorted order.

What about the SUB procedure names, do you want them output in the order they are found in each BAS file, or also sorted before output?


»bp
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Here is a basic starting point in BAT script, see what you think...

@echo off
setlocal EnableDelayedExpansion

set BaseDir=B:\EE\EE29148681

REM Get current date/time
set LocalDateTime=
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
    if not defined LocalDateTime (
        set LocalDateTime=%%A
    )
)

REM Format current date/time as YYYYMMDD_hhmmss
set OutFile=%LocalDateTime:~0,8%_%LocalDateTime:~8,6%

(
    REM Process each file in alphabetic order
    for /F "tokens=*" %%F in ('dir /b /on "%BaseDir%\*.bas"') do (
        set i=0
        REM Extract SUB procedure names and output them to CSV
        for /F "tokens=2 delims=( " %%S in ('findstr /i /r "^SUB +.*^\(" "%%~F"') do (
            set /a i+=1
            echo %%S !i!;%%F
        )
    )
)>"%OutFile%"

Open in new window


»bp
Luis DiazIT consultant

Author

Commented:
Hello Bill,
I did a first test and I get the following:
List-subs.pngDate stamp should be a folder.
Various csv files should be generated in datestamp folder.
If you have questions, please contact me.
Thank you.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
What does each CSV file hold, and how should they be named?


»bp
Luis DiazIT consultant

Author

Commented:
Csv should contains string after Sub in column A and module name in column B.
Csv file should be named as module.
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Okay, give this a try.

@echo off
setlocal EnableDelayedExpansion

REM Get current date/time
set LocalDateTime=
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
    if not defined LocalDateTime (
        set LocalDateTime=%%A
    )
)

REM Define folders to work with
set BaseDir=B:\EE\EE29148681\Files
set DestDir=B:\EE\EE29148681\%LocalDateTime:~0,8%_%LocalDateTime:~8,6%

REM Make sure base folder exists
if not exist "%BaseDir%" (
    echo *ERROR* Base fodler does not exist "%BaseDir%"
    exit /b
)

REM Create destination folder
if not exist "%DestDir%" (
    md "%DestDir%"
)

REM Quit if dest folder could not be created
if not exist "%DestDir%" (
    echo *ERROR* Dest fodler could not be created "%DestDir%"
    exit /b
)

REM Process each file in alphabetic order
for /F "tokens=*" %%F in ('dir /b /on "%BaseDir%\*.bas"') do (
    set i=0
    REM Extract SUB procedure names and output them to CSV
    (
        for /F "tokens=2 delims=( " %%S in ('findstr /i /r "^SUB +.*^\(" "%BaseDir%\%%~F"') do (
            set /a i+=1
            echo %%S !i!;%%F
        )
    )>"%DestDir%\%%~nF.csv"
)

Open in new window


»bp
Luis DiazIT consultant

Author

Commented:
Thank you Bill. Unable to test it right now.
Luis DiazIT consultant

Author

Commented:
Test it and it works!
Thank you again for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial