首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >批处理脚本程序

批处理脚本程序
EN

Stack Overflow用户
提问于 2013-09-24 15:19:25
回答 1查看 96关注 0票数 0

第一次运行时,用户可以选择他们学校的课程类型。

然后(当你进一步查看源代码时)将会出现各种科目的第一次测试的日期。

如果我使用它,它将打印我没有的程序主题。例如,如果我有“法学(Rettslere)”而不是“市场营销”,我不希望市场营销(Markedsforing)被程序主体发现,而只是“法学”。因此,它应该忽略我没有的所有程序课程。

我该怎么做?

具体的问题:我怎么做,它不会输出程序的日志不在programfag.txt文件中?

程序:

代码语言:javascript
复制
echo Rettslære (R)
echo sosialkunnskap (s)
echo markedsforing (m)
echo historie og filosofi (hf)
echo sosialantropologi (sa)
echo psykologi (p)

代码:

代码语言:javascript
复制
    @echo off &setlocal EnableDelayedExpansion
if not exist "%userprofile%/programfag.txt" goto programfag
goto hello


:programfag

echo Rettslære (R)
echo sosialkunnskap (s)
echo markedsforing (m)
echo historie og filosofi (hf)
echo sosialantropologi (sa)
echo psykologi (p)

set /p programfag=What is your programfag (r,s,m,hf,sa,p)?

if %programfag% == r echo rettslare > %userprofile%/programfag.txt
if %programfag% == m echo markedsforing > %userprofile%/programfag.txt
if %programfag% == s echo sosialkunnskap > %userprofile%/programfag.txt
if %programfag% == hf echo Historieogfilosofi > %userprofile%/programfag.txt
if %programfag% == sa echo sosialantropologi > %userprofile%/programfag.txt
if %programfag% == p echo psykologi > %userprofile%/programfag.txt

goto programfag




:hello
set "file_path=.\test2.txt"

if not exist "!file_path!" echo File "!file_path!" Does Not Exist >&2 & exit /b 2
for /f %%F in ("!file_path!") do  set file_path=%%~sfF


copy nul "%TEMP%\~.ddf" >nul

makecab /D RptFileName="%TEMP%\~.rpt" /D InfFileName="%TEMP%\~.inf" -f "%TEMP%\~.ddf">nul
for /f "tokens=3-7" %%a in ('type "%TEMP%\~.rpt"') do (
   if not defined current-date set "current-date=%%e-%%b-%%c"
   if not defined current-time set "current-time=%%d"
   if not defined weekday set "weekday=%%a"
)
del /q "%TEMP%\~.*"
rem echo %weekday% %current-date% %current-time%
set Jan=01
set Feb=02
set Mar=03
set Apr=04
set May=05
set Jun=06
set Jul=07
set Aug=08
set Sep=09
Set Oct=10
set Nov=11
set Dec=12
set auth=Malin Kristiane Pedersen
set abas=0
set auto=%abas%

for /F "tokens=1,2,3 delims=-" %%A in ("%current-date%") do (
    set comparable_date=%%A!%%B!%%C
)
rem echo %comparable_date%
set /a nearest_date=99999999
for /F "tokens=1,2,3 delims=. " %%A in (%file_path%) do (

    set /a possible_nearest_date=%%C%%B%%A

    set /a old_result=!nearest_date!-comparable_date
    set /a new_result=!possible_nearest_date!-comparable_date

    if !new_result! LSS !old_result! set /a nearest_date=!possible_nearest_date!
)
if !nearest_date! EQU 99999999 echo something wrong with the file>&2 && endlocal && exit /b 3

set nearest_date=!nearest_date:~-2!.!nearest_date:~4,2!.!nearest_date:~0,4!
color 4E

echo(
echo(
rem type %file_path%
for /f "tokens=1,2* delims=()" %%L in ('type %file_path%^|find "!nearest_date!"') do ( 

    for /f "tokens=1,2" %%t in  ("%%L") do (

                echo              Neste prove: (!nearest_date!^)   
             echo                    fag:  %%u   
title %%u !nearest_date!                                                 grunder: %auth%        
              echo          Tema:   %%M^ )                      

    )   
)
echo(
echo(
set /p skriva=Do you want to see typical questions about this topic? (Y/N)
if %skriva% EQU Y goto !nearest_date!sporsmaal
if %skriva% EQU y goto !nearest_date!sporsmaal
else
pause>nul
cls



goto hello
exit


:28.10.2013sporsmaal
echo AAA
echo BBB
echo CCC
echo DDD
echo EEE

pause
exit

以下是输出的来源:

代码语言:javascript
复制
     if !nearest_date! EQU 99999999 echo something wrong with the file>&2 && endlocal && exit /b 3

set nearest_date=!nearest_date:~-2!.!nearest_date:~4,2!.!nearest_date:~0,4! color 4E

echo( echo( rem type %file_path% for /f "tokens=1,2* delims=()" %%L in ('type %file_path%^|find "!nearest_date!"') do (

for /f "tokens=1,2" %%t in  ("%%L") do (

            echo              Neste prove: (!nearest_date!^)   
         echo                    fag:  %%u   
title %%u !nearest_date! grunder: %auth% 
echo Tema: %%M^ )

)   
) echo( echo(

注意:

Test2.txt中的示例:

代码语言:javascript
复制
28.10.2013 Norsk (kunnskapsprøve).
29.10.2013 matte (prøve kapittel 1 og kapittel 3,1 - 3,6).

programfag.txt中的示例

代码语言:javascript
复制
markedsforing

正如我所说的,我希望当fag (在源代码中)被显示时,当它在程序中查看时,它只会显示它与programfag.txt中的相同

EN

回答 1

Stack Overflow用户

发布于 2013-09-24 17:53:46

备份"%userprofile%/programfag.txt"文件并尝试此操作。它只打印在"%userprofile%/programfag.txt"文件中找到的内容。

代码语言:javascript
复制
@echo off

>>"%userprofile%/programfag.txt" echo 11/22/2000 sosialkunnskap
>>"%userprofile%/programfag.txt" echo 4/12/2010 historie og filosofi

:programfag

for %%a in (
"Rettslære (R)"
"sosialkunnskap (s)"
"markedsforing (m)"
"historie og filosofi (hf)"
"sosialantropologi (sa)"
"psykologi (p)"
) do for /f "delims= " %%b in ("%%~a") do find "%%b" <"%userprofile%/programfag.txt" >nul && echo %%~a
pause
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18975299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档