我正在尝试制作一个批处理文件,用于打开python文件,来自竞争,在notepadd ++中。不同的阶段有不同的任务。它允许您选择年份和阶段。它还允许您打开它们才能查看。最后认为它会询问您是否要创建丢失的文件。我正在使用exists来检查文件是否存在,notepad ++会自动询问您是否要创建丢失的文件,我想避免这种情况。
@echo off
echo What stage?
SET /p etap=
echo What year?
SET /p rok=
echo Edit? [y/n] ::Open as read only or not.
SET /p mode=
if %mode%==y (
echo Create missing files? [y/n]
SET /p missing=
if %missing%==y (
if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z4.py
if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
) else (
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z4.py if %etap%==3 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z4.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py if %etap%==2 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if exist E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py if %etap%==1 start notepad++ E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py )
) else (
if %etap%==3 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==3 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==3 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if %etap%==3 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z4.py
if %etap%==2 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==2 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==2 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py
if %etap%==1 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z1.py
if %etap%==1 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z2.py
if %etap%==1 start notepad++ -ro -nosession E:\Programs\Python\Programs\Logia\%rok%_e%etap%_z3.py )
start chrome http://logia.oeiizk.waw.pl/nowa/page.php?sr=logia%rok%/%etap%etap
pause
当我运行文件时,它会先询问3个问题并关闭。我认为这是因为括号。
答案 0 :(得分:1)
在解析(parnethesis)块之前,在执行代码之前完成百分比扩展时,它会失败。
因此%missing%
会扩展到执行行if %mode%==y (
之前的值。
为避免这种情况,您可以使用延迟扩展。
setlocal EnableDelayedExpansion
...
if !mode!==y (
echo Create missing files? [y/n]
SET /p missing=
if !missing!==y (
...