sorting - "MMdd"中的昨天日期,具体的输出文件夹选择取决于日期

标签 sorting date powershell video ffmpeg

所以我试图管理闭路电视录像,
到目前为止,我已经在 powershell 中提出了这个代码:

在 MMdd 中获取昨天的日期(今天的版本将是 0516),-> 选择所有以该日期开头的文件 -> 使用 ffmpeg 压缩它们 -> 移动到另一个文件夹 -> 删除源文件

$a = get-date -format "MMdd"
$b = 1
$c = $a - $b
$d = $c.ToString("0000")
$inProcessPath = "sourcepath"
$oldVideos = Get-ChildItem -Include @("$d *") -Path $inProcessPath -Recurse;

Set-Location -Path 'D:\ffmpeg\bin';

foreach ($oldVideo in $oldVideos) {
    $newVideo = [io.path]::ChangeExtension($oldVideo.FullName, '.avi')


    $ArgumentList = '-i "{0}" -b 200000 "{1}"' -f $oldVideo, $newVideo;


    Start-Process -FilePath "D:\ffmpeg\bin\ffmpeg.exe" -ArgumentList $ArgumentList -Wait -NoNewWindow;
}

Robocopy D:\ffmpeg\bin\ntv D:\newpaths "$d *.avi" /mov

get-childitem "sourcepath" -include "$d *.mp4" -recurse | foreach ($_) {remove-item $_.fullname}

但是,在测试阶段,我意识到当有一个月切换时,我的实现将无法工作,因为从 0601 开始,它不会产生 0531,而是 0600。

我还需要根据当前月份将转换后的文件移动到一个目录,所以如果我有文件夹 May、June 等。我需要以 05 开头的文件转到 May 文件夹,依此类推。

有人可以在代码或建议中帮助我完成我的任务吗

我的编程知识不足以解决这个问题。

主要目标是自动化

第一部分由@dotnetom 提供
这有效:
$d = (get-date).AddDays(-1).ToString("MMdd")

对于第二部分,我想出了这个
    $a = (get-date).AddDays(-1).ToString("MMMM")

Robocopy D:\Main\AdWords\ffmpeg\bin\ntv "D:\path\$a" "$d *.avi" /mov

最佳答案

要获取前一天,您可以使用函数 AddDays获取昨天的日期,然后根据您的需要对其进行格式化:

$d = (get-date).AddDays(-1).ToString("MMdd")

如果我们分解这段代码,组件是:
$currentDay = get-date                 # current day
$yesterday = $currentDay.AddDays(-1)   # yesterday
$formattedYesterday = $yesterday.ToString("MMdd")  #yesterday formatted to MMdd

关于sorting - "MMdd"中的昨天日期,具体的输出文件夹选择取决于日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37266908/

相关文章:

R如何根据上下文填写缺失的日期

Powershell:获取目录中最后一个按字母数字排序的文件的路径

sql-server-2008 - SQL 服务器 2008 : how to get the "Messages" tab (in Management Studio) output with powershell

powershell - 显示与字符串模式匹配的所有服务名称

jquery - 如何为 jQuery Tablesorter 中的每一列设置默认排序顺序?

javascript - 使用 React Native 对电话联系人进行排序

algorithm - 到位排序

php - 字母数字数组排序(警告 : spaces as a thousands separator in numbers)

在 Linux 系统中更改日期,但重启后新日期丢失

javascript - 日期格式正则表达式匹配日期分隔符