windows 在Powershell中复制创建日期时出错:此时意外出现.CreationTime

wpx232ag  于 2023-01-27  发布在  Windows
关注(0)|答案(1)|浏览(186)

我尝试复制原始文件的日期转换后,他们与ffmpeg,但它给我以下错误:"此时意外出现. CreationTime"。
脚本:

set /A g=5
set /A crf=20
set encoding=x265
set targetFolder=.\converted

for %%f in (.\*.mp4) do (
    echo "fullname: %%f"
    echo "name: %%~nf"
    ffmpeg -i "%%f" -vcodec "lib%encoding%" -crf %crf% -g %g% "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4"
    $(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").CreationTime=(Get-Item "%%f").CreationTime
    $(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").LastWriteTime=(Get-Item "%%f").LastWriteTime
    $(Get-Item "%targetFolder%\%%~nf.crf%crf%.%encoding%.mp4").LastAccessTime=(Get-Item "%%f").LastAccessTime
)

注意:在循环之外,该命令有效:

$(Get-Item ".\converted\VID_20200712_103210.crf20.x265.mp4").CreationTime=(Get-Item ".\VID_20200712_103210.mp4").CreationTime
jutyujz0

jutyujz01#

我将我的脚本更新为PowerShell脚本,现在它可以正常工作了:

$g=5
$crf=20
$encoding="x265"
$targetFolder=".\converted"

foreach ($f in (Get-ChildItem -Path ".\*.mp4")) {
    Write-Host "fullname: $f"
    Write-Host "name: $($f.BaseName)"
    ffmpeg -i "$f" -vcodec "lib$encoding" -crf $crf -g $g "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4"
    (Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").CreationTime=(Get-Item $f).CreationTime
    (Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").LastWriteTime=(Get-Item $f).LastWriteTime
    (Get-Item "$($targetFolder)\$($f.BaseName).crf$crf.$encoding.mp4").LastAccessTime=(Get-Item $f).LastAccessTime
}

相关问题