该脚本生成一个音乐列表,这些音乐的 LUFS 值将被标准化,但是,首先我需要从该列表中删除标题。标题包含三行:第一行是空白的,第二行包含 Music 和 LUFS 列,第三行包含破折号。
我尝试使用此链接中的命令:
删除文本文件的顶行
列出txt文件内容:
Music LUFS
------ ----
05 - Earth Wind and Fire - September (The Reflex Revision).mp3 -9,6
脚本:
# Receive parameter sent by batch file
Param(
[decimal]$_vLUF
)
[decimal]$vLUFps = $_vLUF
$files = "C:\Users\$env:username\Desktop\Logs_LUFS\List Music for normalization.txt"
$fileSelect = "C:\Users\$env:username\Desktop\Logs_LUFS\Selection List.txt"
# Read log files and generate the file List Music for normalization.txt
$logMatches = Select-String -Path "C:\Users\$env:username\Desktop\Logs_LUFS\*.*" -Pattern '(?<I>^ +I:) +(?<LUFS>.+)|(?<I>^Input Integrated:) +(?<LUFS>.+)' -List | Select-Object -Property FileName -ExpandProperty Matches
$results = foreach ($log in $logMatches) {
$pos = $log.Filename.IndexOf("_")
$leftPart = $log.Filename.Substring(0, $pos)
$rightPart = $log.Filename.Substring($pos+1)
$LUFS = $log.Groups | Where-Object { $_.Name -eq "LUFS" }
[PSCustomObject]@{
Música = $rightPart
LUFS = [decimal]$($LUFS.Value -replace " .*")
}
}
$vLUFpsLess= ($vLUFps)+ (-0.9)
$vLUFpsGreat= ($vLUFps)+ (-0.5)
$results | Where-Object {($_.LUFS -lt $vLUFpsLess) -or ($_.LUFS -gt $vLUFpsGreat) } | Out-file $files
# Get content from $files to $fileSelect
Set-Content $fileSelect -Value (Get-Content $files)
# Removes blank line, column titles and dashes in $fileSelect
get-content $fileSelect |
select -Skip 3 |
set-content "$fileSelect-temp"
move "$fileSelect-temp" $fileSelect -Force
向此脚本发送参数的批处理文件中的命令:
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -Verb RunAs powershell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File \"D:\z_Batchs e Scripts\Batchs\Normaliza_LUFS\ArqsNorms_LUFS_pass.ps1\" -_vLUF %_vLUF%'"
当我运行命令删除前三行时,它说Selection List.txt-temp
找不到该文件,因为它不存在。如果文件Selection List.txt-temp
刚刚创建,怎么会发生这种情况?
错误信息:
move : Unable to find the path 'C:\Users\CMG\Desktop\Logs_LUFS\Selection List.txt-temp' because he doesn't exist.
No D:\z_Batchs e Scripts\Batchs\Normaliza_LUFS\ArqsNorms_LUFS_pass.ps1:45 character:1
+ move "$fileSelect-temp" $fileSelect -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
是否有其他命令可以用来删除文本文件的前三行?
答案1
工作原理如下:
Get-ChildItem $fileSelect | ForEach-Object {
Set-Content (Get-Content $_ | Select-Object -Skip 3) -Path $_
}