0

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

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

如果我使用它,它将打印我没有的程序主题。例如,如果我有“jurisprudence(rettslere)”而不是“marketing”,我不希望程序主题找到marketing(markedsforing),而只有“jurisprudence”。因此它应该忽略我没有的所有程序课程。

我该怎么做呢

特殊问题:我该怎么做才能输出不在 programfag.txt 文件中的程序的课程?

程序的:

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

代码:

    @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

这是输出的来源:

     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 中的示例:

28.10.2013 Norsk (kunnskapsprøve).
29.10.2013 matte (prøve kapittel 1 og kapittel 3,1 - 3,6).

programfag.txt 中的示例

markedsforing

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

4

1 回答 1

0

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

@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
于 2013-09-24T09:53:46.117 回答