powershell自动递增001

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

这是我想要实现的。捕获屏幕并将其另存为$ username- $ date-000.jpg每次保存文件时都需要自动增加000。 (即000,001,002)

我已尝试自动生成数字。我应该怎么办?如何自动增加数字?

$Path = read-host "Screenshot will save to - [1] Desktop or [2] C:\" 
switch ($Path)
{
        1
        {
        $Path = "$($env:USERPROFILE)\Desktop\"
        }
        2
        {
        $Path = "C:\"
        }
}
$X = 0
$FileName = %{"$env:USERNAME-$(get-date -f MM-dd)-$(($X+1).ToString("000")).jpg"}
$File = "$Path\$FileName"
powershell auto-increment
2个回答
0
投票

[当给用户选择路径时,我认为您需要更多(3)变量来跟踪该路径的当前序列号。


0
投票

这可能不是理想的方法,但仍然有效:

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