使用Octal Number 08和09以及SCHTASKS

问题描述 投票:0回答:2

我有我认为的工作脚本。随机决定尝试09月,但失败了。 08年也失败了。

谷歌搜索等告诉我这是因为Octal Numbers是我所知道的基础8。

我不确定如何最好地解决这个问题以满足我的需求,并且可以使用一些建议。

此日期用于通过SCHTASKS创建任务,该任务需要2位数的月/日和4位数年份

当08和09用于本月时,它会一直循环回到开头。我认为它也适用于这一天。不确定其他数字可能会受到影响。

:SETDATE
CLS
ECHO.
ECHO Date must be 2 digit Month/Day and 4 digit Year
ECHO.
ECHO.
SET /P SETMONTH=Enter 2 digit month for the restart (01-12):
ECHO.
SET /P SETDAY=Enter 2 digit day for the restart (01-31):
ECHO.
SET /P SETYEAR=Enter 4 digit year for the restart (2019-2025):

IF %SETMONTH% LSS 1 GOTO SETDATE
IF %SETMONTH% GTR 12 GOTO SETDATE
IF %SETDAY% LSS 1 GOTO SETDATE
IF %SETDAY% GTR 31 GOTO SETDATE
IF %SETYEAR% LSS 2019 GOTO SETDATE
IF %SETYEAR% GTR 2025 GOTO SETDATE
batch-file octal
2个回答
0
投票

以为我会发布一个似乎符合我需求的解决方案。它没有考虑到每一个可能的输入,但它确实解决了我在08和09的问题。它删除了前导0如果有一个然后它将处理正常。

:SETDATE
CLS
ECHO.
ECHO Date must be 2 digit Month/Day and 4 digit Year
ECHO.
ECHO.
SET /P SETMONTH=Enter 2 digit month (01-12):
ECHO.
SET /P SETDAY=Enter 2 digit day (01-31):
ECHO.
SET /P SETYEAR=Enter 4 digit year (2019-2025):

IF %SETMONTH% == 0 (
    SET NEWMONTH=0
) ELSE (
    IF "%SETMONTH:~0,1%" == "0" (
        SET NEWMONTH=%SETMONTH:~1%    
    ) ELSE (
        SET NEWMONTH=%SETMONTH%
    )    
)
IF %SETDAY% == 0 (
    SET NEWDAY=0
) ELSE (
    IF "%SETDAY:~0,1%" == "0" (
        SET NEWDAY=%SETDAY:~1%    
    ) ELSE (
        SET NEWDAY=%SETDAY%
    )    
)
IF %SETYEAR% == 0 (
    SET NEWYEAR=0
) ELSE (
    IF "%SETYEAR:~0,1%" == "0" (
        SET NEWYEAR=%SETYEAR:~1%    
    ) ELSE (
        SET NEWYEAR=%SETYEAR%
    )    
)

IF %NEWMONTH% LSS 1 GOTO SETDATE
IF %NEWMONTH% GTR 12 GOTO SETDATE
IF %NEWDAY% LSS 1 GOTO SETDATE
IF %NEWDAY% GTR 31 GOTO SETDATE
IF %NEWYEAR% LSS 2019 GOTO SETDATE
IF %NEWYEAR% GTR 2025 GOTO SETDATE

0
投票

虽然从技术上讲这不是你想要的答案类型,但我决定将其添加为一个想法。

这是一个独立的批处理文件,旨在为最终用户提供GUI日历供您选择。它使用PowerShell,据我所知,应该使用Windows 7,即PowerShell 2.0。

<# :DSel
@Echo Off
Set "_="&For /F Delims^=^ EOL^= %%A In ('PowerShell -NoP -C^
 "IEx([IO.File]::ReadAllText('%~f0'))"') Do Set "_=%%A"
If Not Defined _ GoTo DSel
Echo You selected %_%
Pause
Exit /B
#>
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object Windows.Forms.Form

$form.Text = 'Select a date'
$form.Size = New-Object Drawing.Size @(243,230)
$form.StartPosition = 'CenterScreen'

$calendar = New-Object System.Windows.Forms.MonthCalendar
$calendar.ShowTodayCircle = $false
$calendar.MaxDate = ((Get-Date).AddYears(5)).AddDays(-1)
$calendar.MinDate = Get-Date
$calendar.MaxSelectionCount = 1
$form.Controls.Add($calendar)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(38,165)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(113,165)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Today'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

$form.ControlBox = $false
$form.Topmost = $true

$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    $date = $calendar.SelectionStart
    Write-Host $($date.ToString('MM-dd-yyyy'))
}

如您所知,您已了解PowerShell,请将其留给您对PowerShell进行任何必要的修改。

© www.soinside.com 2019 - 2024. All rights reserved.