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

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
LVL 1
LD16Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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 ConsultantCommented:
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
LD16Author 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 Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Bill PrewIT / Software Engineering ConsultantCommented:
What does each CSV file hold, and how should they be named?


»bp
LD16Author Commented:
Csv should contains string after Sub in column A and module name in column B.
Csv file should be named as module.
Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Thank you Bill. Unable to test it right now.
LD16Author Commented:
Test it and it works!
Thank you again for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.