-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_script.bat
More file actions
51 lines (44 loc) · 1.01 KB
/
run_script.bat
File metadata and controls
51 lines (44 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@echo off
REM Resolve this script’s directory and change into it
pushd %~dp0
REM Ensure “scripts” is a Python package
if not exist "scripts\" (
echo Error: scripts\ directory not found.
exit /b 1
)
if not exist "scripts\__init__.py" (
echo Error: scripts\__init__.py not found.
exit /b 1
)
REM Collect all .py files in scripts\ excluding __init__.py
setlocal enabledelayedexpansion
set count=0
for %%F in ("scripts\*.py") do (
if /I not "%%~nxF"=="__init__.py" (
set /A count+=1
set "file!count!=%%~nxF"
)
)
if %count% EQU 0 (
echo No Python files found in scripts\.
exit /b 1
)
REM Display menu
echo Select a script to run:
for /L %%i in (1,1,%count%) do (
echo %%i^) !file%%i!
)
:prompt
set /p choice=Enter number:
if not defined file%choice% (
echo Invalid selection. Try again.
goto prompt
)
REM Strip .py extension and run
set "fname=!file%choice%!"
set "mod=!fname:.py=!"
python -m scripts.%mod%
set exitCode=%ERRORLEVEL%
endlocal
popd
exit /b %exitCode%