AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1670826

Clamarc's questions

Martin Hope
Clamarc
Asked: 2024-05-26 07:59:16 +0800 CST

Ffmpeg LUFS Loudnorm 标准化结果

  • 5

我使用 Ffmpeg 中的 Loundnorm 过滤器,使用双通道方法对包含三个音频(Music1.mp3、Music2.mp3 和 Music3.mp3)的文件夹中的 LUFS 进行标准化。

所有音频文件的 LUFS 和真实峰值都相同:
LUFS -10.0 and True Peak -0.5

代码:

md "C:\Users\%username%\Desktop\Temp_normalizing_lufs"    ------> temp folder audio files being normalized   
pushd "%Userprofile%\Desktop\Audios LUFS"                 ------> folder with the original audio files

                                                                                                      __
FOR /F "delims=" %%a in ('where .:*.mp3 ^|findstr /vi "_LOUDNORM  _EBU"') DO (                          |                
  SET "filename=%%~na"                                                                                  |
  ffmpeg -hide_banner -i "%%a" -af "[0:a]loudnorm=print_format=summary" -f null NUL 2> "%%~na.log"      |   
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Integrated" "%%~na.log"') DO (SET II=%%b)               |
  @FOR /F "tokens=4" %%b IN ('FINDSTR /C:"Input True Peak" "%%~na.log"') DO (SET ITP=%%b)               |  set original audio files values  
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET ILRA=%%b)                    |  to use as parameters in loudnorm
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Threshold" "%%~na.log"') DO (SET IT=%%b)                |
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Target Offset" "%%~na.log"') DO (SET TO=%%b)                  |
  DEL "%%~na.log"                                                                                     __|

  SETLOCAL ENABLEDELAYEDEXPANSION
  FOR /F "tokens=1,2 delims=," %%b IN ('ffprobe -v 0 -select_streams a -show_entries "stream=bit_rate,sample_rate" -of "csv=p=0" "!filename!.mp3"')     ----> getting the sample rate and bitrate of the original audio file to use as parameters in loudnorm
  DO (  
      ffmpeg -hide_banner -i "!filename!.mp3" -af "loudnorm=linear=true:I=!-10.0!:LRA=11:tp=!-0.5!:measured_I=!II!:measured_LRA=!ILRA!:measured_tp=!ITP!:measured_thresh=!IT!:offset=!TO!:print_format=summary" -c:v copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -acodec mp3 -b:a %%c -ar:a %%b "C:\Users\%username%\Desktop\Temp_normalizing_lufs\!filename!.mp3"
     )
  ENDLOCAL
)

xcopy "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.mp3" "C:\Users\%username%\Desktop\Normalized Audios Lufs\LOUDNORM\MP3\LUFS %-10.0%" /y /s /i   ----> copying the audio files from the temporary folder to the final folder

                                                                __
del /q "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.*"    |
rmdir "C:\Users\%username%\Desktop\Temp_normalizing_lufs" /s /q   |  Removing the temporary folder from the desktop
                                                                __|

Music1 音频文件的结果:

Input Integrated:    -13.3 LUFS
Input True Peak:      +1.6 dBTP
Input LRA:             6.1 LU
Input Threshold:     -23.4 LUFS

Output Integrated:   -11.8 LUFS
Output True Peak:     -0.5 dBTP
Output LRA:            4.5 LU
Output Threshold:    -21.9 LUFS

Normalization Type:   Dynamic
Target Offset:        +1.8 LU

为什么上面的Output Integrated 值没有达到LUFS -10.0?
PS:即使我将 LUFS 更改为 -9.0,Intregede 输出值仍保持不变 -11.8 LUFS。

我使用volumeDetect函数分析了Music1音频,结果如下:

Output #0, null, to 'NUL':
  Metadata:
    title           : Music1
    TKEY            : F#m
    comment         : 
    album           : Electro's Remix
    genre           : Electro
    artist          : Chic
    encoder         : Lavf59.17.102
  Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.21.100 pcm_s16le
size=N/A time=00:00:00.02 bitrate=N/A speed=2.61e+04x    
size=N/A time=00:04:30.26 bitrate=N/A speed= 541x    
size=N/A time=00:05:44.60 bitrate=N/A speed= 543x    
video:0kB audio:59364kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_volumedetect_0 @ 0000022928c2e1c0] n_samples: 30394368
[Parsed_volumedetect_0 @ 0000022928c2e1c0] mean_volume: -15.7 dB
[Parsed_volumedetect_0 @ 0000022928c2e1c0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0000022928c2e1c0] histogram_0db: 13190
[Parsed_volumedetect_0 @ 0000022928c2e1c0] histogram_1db: 37702

在上面的结果中,max_volume参数的值为 0.0 dB。
这可能是归一化未达到我设置的-10.0 的问题吗?

我在 Music1 中应用了压缩器,参数如下:

Threshold: -25.00 db
Ratio  : 2.00:1
Attack : 0.25 ms
Release: 20.0 ms 

VolumeDetect 函数的结果是:

Output #0, null, to 'NUL':
  Metadata:
    title           : Music1
    TKEY            : F#m
    comment         : 
    album           : Electro's Remix
    genre           : Electro
    artist          : Chic
    encoder         : Lavf59.17.102
  Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
      Metadata:
        encoder         : Lavc61.5.104 pcm_s16le
[Parsed_volumedetect_0 @ 0000021002da5180] n_samples: 30392156
[Parsed_volumedetect_0 @ 0000021002da5180] mean_volume: -17.1 dB
[Parsed_volumedetect_0 @ 0000021002da5180] max_volume: -0.9 dB
[Parsed_volumedetect_0 @ 0000021002da5180] histogram_0db: 2
[Parsed_volumedetect_0 @ 0000021002da5180] histogram_1db: 9

请注意上面max_volume值已更改为-0.9 db

我使用参数LUFS = -10.0和执行音频标准化True Peak = -0.0:

Input Integrated:    -14.6 LUFS
Input True Peak:      -0.7 dBTP
Input LRA:             4.6 LU
Input Threshold:     -24.6 LUFS

Output Integrated:   -10.5 LUFS
Output True Peak:     +0.0 dBTP
Output LRA:            3.8 LU
Output Threshold:    -20.5 LUFS

Normalization Type:   Dynamic
Target Offset:        +0.5 LU

请注意,上面输出积分的结果要好得多。

Music2 音频文件的结果:

Input Integrated:     -6.0 LUFS
Input True Peak:      +4.9 dBTP
Input LRA:             4.8 LU
Input Threshold:     -16.3 LUFS

Output Integrated:   -10.0 LUFS
Output True Peak:     -0.5 dBTP
Output LRA:            4.3 LU
Output Threshold:    -20.3 LUFS

Normalization Type:   Dynamic
Target Offset:        +0.0 LU

Music3 音频文件的结果:

Input Integrated:     -5.9 LUFS
Input True Peak:      +0.6 dBTP
Input LRA:             4.5 LU
Input Threshold:     -16.0 LUFS

Output Integrated:   -10.0 LUFS
Output True Peak:     -3.5 dBTP
Output LRA:            4.5 LU
Output Threshold:    -20.1 LUFS

Normalization Type:   Linear
Target Offset:        -0.0 LU

为什么在上述音频文件中,Music2 使用归一化类型:动态,而 Music3 使用归一化类型:线性?...什么规则定义了何时为动态、何时为线性?

windows-10
  • 1 个回答
  • 59 Views
Martin Hope
Clamarc
Asked: 2024-05-03 06:44:11 +0800 CST

Powershell-仅保留txt文件中包含某些选定单词的行

  • 6

我有一个 txt 文件,我想只保留其中的几行

我想要一个命令来改变这个

txt 文件:

;FFMETADATA1
title=TNT
disc=01
comment=
lyrics-eng=
\

\

\
album=Classic
genre=Older
artist=ACDC
encoder=Lavf59.17.102

进入这个:

;FFMETADATA1
title=TNT
encoder=Lavf59.17.102

我使用了这个链接中的命令:

仅保留 txt 文件中包含特定单词/字符的行 (Powershell)(Windows 批处理文件)

PowerShell -Command "gci *.txt | foreach { (cat $_.FullName | ? { $_ -like '*;FFMETADATA1*' }) | set-content $_.FullName}"

但txt文件是这样的:

;FFMETADATA1

如何使用命令使txt文件有行;FFMETADATA1 title=和encoder=?

windows
  • 3 个回答
  • 152 Views
Martin Hope
Clamarc
Asked: 2024-04-22 00:37:50 +0800 CST

Ffmpeg - 如何从 mp3 轨道输出中仅删除一个标签?

  • 5

我需要从输出轨道中删除歌词标签。
曲目信息:

Stream mapping:
  Stream #0:1 -> #0:0 (copy) 
  Stream #0:0 -> #0:1 (mp3 (mp3float) -> mp3 (libmp3lame))  
Output #0, mp3, to 'D:\My_music\Music_no_lyrics.mp3':
  Metadata:
    TIT2        : Music

    lyrics-eng  :                            _
                :                             |
                :                             |
                :                             |  I want remove this tag
                :                             |
                : musics.org                 _|    
                                             
     TALB       : Classic Musics
     TCON       : Classic
     TPE1       : Music
     TSSE       : Lavf59.17.102

我的命令:

ffmpeg -hide_banner -i "D:\My_music\Music.mp3" -c:v copy -id3v2_version 3 -metadata lyrics-eng="" -acodec mp3 -b:a 320 -ar:a 44100 "D:\My_music\Music_no_lyrics.mp3"

我怎样才能做到这一点?

ffmpeg
  • 1 个回答
  • 25 Views
Martin Hope
Clamarc
Asked: 2022-10-20 11:07:51 +0800 CST

带有负数的 Powershell 操作

  • 5

我进行了搜索,但只找到了与 excel 相关的答案。

目标:
计算原始音频 LUFS 值与用户定义的 LUFS 值之间的差异。这两个值都是负数,我使用一个运算来计算这两个值之间的差异,其中所有减法结果小于 -0.5 的音频都将被忽略。

注:
1 - 通过音频日志检查原始 LUFS 值;
2 - 用户定义的 LUFS 值由 powershell 脚本通过参数接收。

脚本:

Param(
   [decimal]$env:_vLUF   
)

[decimal]$userLUFS = $env:_vLUF

$results = " "
$location = "C:\Users\$env:username\Desktop\Áudios LUFS\"
$logSaida = "C:\Users\$env:username\Desktop\Logs_LUFS\"

$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 " .*")
        }
    }


#                      COMMAND to the subtraction:
$results | Where-Object {( ($_.LUFS -($userLUFS)) -lt -0.5)} | Out-File $files

问题:
当原始LUFS值大于用户定义的LUFS值时,减法正确,见下图:

原始 LUFS ($_.LUFS):- 12.0
用户定义的 LUFS ($userLUFS):-8.8

在此处输入图像描述

当用户定义的值大于原始 LUFS 值时,即使两个值都是负数,减法也会在结果中返回正值,见下文:

原始 LUFS ($_.LUFS):-8.8
用户定义的 LUFS ($userLUFS):- 12.0

在此处输入图像描述

似乎因为值是负数,它认为 -8.8 大于 -12.0 因为它更接近 0.0,但我想要的是结果,无论接收到的值的顺序如何,总是返回负数结果。我尝试将结果乘以 -1,但它只是扭转了问题。如何使结果始终返回负值?

powershell-5.0
  • 1 个回答
  • 40 Views
Martin Hope
Clamarc
Asked: 2022-06-19 10:41:29 +0800 CST

在 timeout 命令中仅显示倒计时

  • 8

我需要在没有消息的情况下运行 timeout 命令press a key to continue...

我尝试了该命令timeout /t 10 > null,但它对我不起作用,因为它会将消息和倒计时一起剥离。

默认命令:

@echo off
echo Wait...
timeout /t 10
exit

结果:

Wait...
Waiting 9 seconds, press a key to continue...

我需要的:

Wait...
Waiting 9 seconds

如何使 timeout 命令只显示倒计时而不显示消息press a key to continue ...?

windows-10 batch-file
  • 3 个回答
  • 662 Views
Martin Hope
Clamarc
Asked: 2022-06-10 23:52:30 +0800 CST

如何使批处理文件命令等待powershell脚本完成

  • 5

我在一个批处理文件中运行了两个命令,但我需要该del命令来等待执行 powershel 脚本。

我尝试使用以下链接中的命令,但没有成功:
the-batch-script-to-wait

批处理文件:

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%'"

del /q "C:\Users\%username%\Desktop\Logs_LUFS\LOG_*.*"

如何使del命令仅在 powershell 脚本完成后运行?

windows-10 batch-file
  • 1 个回答
  • 491 Views
Martin Hope
Clamarc
Asked: 2022-06-04 21:32:40 +0800 CST

删除txt文件中文件扩展名后的空格

  • 5

我需要从我的 List.txt 中删除文件扩展名之后的所有内容,保留扩展名。

我尝试使用链接中的命令失败:
how-to-use-powershell-to-remove-space-from-the-end-of-a-line
powershell-trim-remove-all-characters-after-a-细绳

列表:

05 - Earth Wind and Fire - September (The Reflex Revision).mp3                                   -9,6
06 - Electric Light Orchestra - Last Train To London (Bootleg Extended Dance Remix).flac         -9,1
08 - Kool & The Gang - Get Down On It (Soul Funk House Remix).wav                               -10,7

我需要的:

05 - Earth Wind and Fire - September (The Reflex Revision).mp3  
06 - Electric Light Orchestra - Last Train To London (Bootleg Extended Dance Remix).flac
08 - Kool & The Gang - Get Down On It (Soul Funk House Remix).wav

我尝试了命令,但没有成功:

$content = Get-Content $files
$content | Foreach {$_.Substring(0, $_.IndexOf('.mp3', '.flac', '.wav' ))} | Set-Content $files

文件扩展名后如何删除,保留扩展名?

windows-10 script
  • 1 个回答
  • 186 Views
Martin Hope
Clamarc
Asked: 2022-06-04 09:27:03 +0800 CST

基于不在 List.txt 中的文件夹中的文件删除

  • 6

目标:
删除文件夹中未在 List.txt 文件中列出的音频文件

读取 List.txt 以与音频文件夹中的文件进行比较,并删除列表中未列出的文件。

List.txt 内容:

05 - Earth Wind and Fire - September (The Reflex Revision).mp3
Electric Light Orchestra - Last Train To London (Bootleg Extended Dance Remix).flac
120 - Kool & The Gang - Get Down On It (Soul Funk House Remix).wav
$files = "C:\Users\$env:username\Desktop\Logs_LUFS\List Audio Files for Normalization.txt"
$location = "C:\Users\$env:username\Desktop\LUFS Audios\"

Get-Content $files | % {               
    $result = Get-ChildItem -Recurse "$location*$_*" 
    If(!$result) {
       Remove-Item $location* $result.Fullname
    }
}

在删除命令中,将出现以下消息:
Cannot bind argument to 'Path' parameter because it is null

当值为 !$Resulttrue 时,从音频文件夹中删除文件的命令是什么?

windows-10 script
  • 1 个回答
  • 177 Views
Martin Hope
Clamarc
Asked: 2022-05-26 07:54:25 +0800 CST

在文本文件中更改名称

  • 5

我有混合音乐项目,软件会生成每个项目中歌曲的 txt 文件列表。问题是生成的列表仅包含每首歌曲名称的前 36 个字符。

我需要更正 txt 文件中的名称,以便它们与原始文件的名称相同,并且我的脚本可以使用列表复制文件。

我在两个块中创建了一个脚本,在第一个块中,我读取了原始文件并生成了一个与 txt 文件中的名称同名的变量。

First block (what I managed to do):
读取原始音乐文件夹中的原始文件,并创建与 List.txt 文件中的变量同名的变量。

Goal of the first block (what I couldn't do):
当此块中变量的名称与 List.txt 中的名称相同时,脚本会将 List.txt 中的名称更改为与该变量相关的原始文件的全名。因此,可以在第二个块中读取 List.txt 文件,其中包含正确的名称。

注意:
可能会出现Original Musics文件夹中有两个同名文件,但版本不同,这种情况下,这两个文件的两个全名必须在List.txt文件中才能复制到目的地文件夹。例如。

List.txt 文件中的名称:
Got To Be Real (CM_Gex Bootleg Exten

原始名称(原始音乐文件夹中的全名):

Cheryl Lynn - Got To Be Real (CM_Gex Bootleg Extended SHORT Re Mix).mp3
Cheryl Lynn - Got To Be Real (CM_Gex Bootleg Extended LONG Re Mix).mp3

变量 $ShortOriginalSongName:

Got To Be Real (CM_Gex Bootleg Exten
Got To Be Real (CM_Gex Bootleg Exten

由于是同一个文件,区别在于一个是长版,一个是短版,两个全名都必须在List.txt文件中,即除了在list.txt中改名字,当文件相同时,脚本必须在 List.txt 中包含原始全名

脚本:

$files = "C:\Users\$env:username\Desktop\List.txt"
$location = "G:\Original Musics\"
$destination = "C:\Users\$env:username\Desktop\Copy Selected Musics\"


# First block:
Get-ChildItem -Recurse $location* -Include *.mp3 | % {
    $ShortOriginalSongName = $_.Basename.Split("-")[1].Trim();
    If ($ShortOriginalSongName.Length -gt 36) {$ShortOriginalSongName = $ShortOriginalSongName.Substring(0, 36)};
    };

# Second Block:
Get-Content $files | % {

  $result = gci -recurse "$location*$_" -Include *.mp3
  
  If($result) { 
    Add-Content $destination"AddList.txt" -Value $result.Fullname
    $musicName = $result.Name    
    $tot+=1       
    Write-Host -ForegroundColor Green "$musicName found on $location!"
    Write-Host "$musicName copied to $destination..."
    Copy-Item $result.FullName -Destination $destination\$($_.Name)
  } 
}

Second Block:
读取使用第一个块中歌曲的正确名称生成的 List.txt 文件,并将原始文件复制到 Copy Selected Musics 文件夹。

windows-10 shell-script
  • 1 个回答
  • 64 Views
Martin Hope
Clamarc
Asked: 2022-05-22 07:12:18 +0800 CST

从另一个文件夹运行批处理文件

  • 5

包含批处理文件的文件夹和包含将被规范化的音频文件的文件夹位于桌面上。

当我将包含批处理文件的文件夹移动到另一个位置,例如 D:\ 并运行批处理文件时,它说它没有找到桌面文件夹中的音频文件。

批处理在执行将读取桌面文件夹中的音频文件的 FOR 命令时取消:

FOR /F "delims=" %%a in ('dir /b *.flac ^|find /v /i "_LOUDNORM" ^|find /v /i "_EBU"') DO

根据下面链接中的信息,我尝试更改放置桌面文件夹的绝对路径的 FOR 命令,但即使如此,该命令也找不到该文件:

命令提示符目录-b

FOR /F "delims=" %%a in ('dir /b C:\Users\CMG\Desktop\Audios to convert\*.flac ^|find /v /i "_LOUDNORM" ^|find /v /i "_EBU"') DO

或者

FOR /F "delims=" %%a in ('dir /b "C:\Users\CMG\Desktop\Audios to convert\*.flac" ^|find /v /i "_LOUDNORM" ^|find /v /i "_EBU"') DO

如何使批处理文件在目录 D:\ 中正常运行?

完整命令:

FOR /F "delims=" %%a in ('dir /b *.flac ^|find /v /i "_LOUDNORM" ^|find /v /i "_EBU"') DO (
  SET "filename=%%~na"   
  ffmpeg -hide_banner -i "%%a" -af "[0:a]loudnorm=print_format=summary" -f null NUL 2> "%%~na.log"
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Integrated" "%%~na.log"') DO (SET II=%%b)
  @FOR /F "tokens=4" %%b IN ('FINDSTR /C:"Input True Peak" "%%~na.log"') DO (SET ITP=%%b)
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET ILRA=%%b)
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Threshold" "%%~na.log"') DO (SET IT=%%b)
  @FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Target Offset" "%%~na.log"') DO (SET TO=%%b)
  DEL "%%~na.log"
  SETLOCAL ENABLEDELAYEDEXPANSION
  ECHO !II!   Input Integrated
  ECHO !ITP!  Input True Peak
  ECHO !ILRA! Input LRA
  ECHO !IT!   Input Threshold
  ECHO !TO!   Target Offset
  FOR /F "tokens=1,2 delims=," %%b IN ('ffprobe -v 0 -select_streams a -show_entries "stream=sample_fmt,sample_rate" -of "csv=p=0" "!filename!.flac"') DO (
  ffmpeg -hide_banner -i "!filename!.flac" -af "loudnorm=linear=true:I=!_vLUF!:LRA=11:tp=!_vPEAK!:measured_I=!II!:measured_LRA=!ILRA!:measured_tp=!ITP!:measured_thresh=!IT!:offset=!TO!:print_format=summary" -c:v copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -map 0:0 -c:a flac -sample_fmt:a %%b -ar:a %%c "C:\Users\%username%\Desktop\Normalizando_lufs\!filename!.flac"
  )
  ENDLOCAL
)
windows batch
  • 1 个回答
  • 182 Views
Martin Hope
Clamarc
Asked: 2022-05-21 07:21:40 +0800 CST

Powershell 更新

  • 5

我的PowerShell版本是:

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

我有以下命令将更新到最新版本:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

我可以使用上述命令来更新我的 Powershel,还是有其他方法可以做到这一点?

如果我更新 powershel,我已经拥有的脚本会正常工作吗?

windows-10 powershell
  • 2 个回答
  • 383 Views
Martin Hope
Clamarc
Asked: 2022-05-15 08:09:47 +0800 CST

删除txt文件中空行的命令不适用于文件路径中的变量

  • 6

删除 List.txt 文件中空行的命令,当我使用 variable 时不起作用$env:username。

作品:在文件路径中使用 CMG 用户名。

$linblk = [System.IO.File]::ReadAllText('C:\Users\CMG\Desktop\List.txt');$linblk = $linblk.Trim();[System.IO.File]::WriteAllText('C:\Users\CMG\Desktop\List.txt', $linblk)

不起作用:$env:username在文件路径中使用变量:

$linblk = [System.IO.File]::ReadAllText('C:\Users\$env:username\Desktop\List.txt');$linblk = $linblk.Trim();[System.IO.File]::WriteAllText('C:\Users\$env:username\Desktop\List.txt', $linblk)
Exception when calling "ReadAllText" with "1" argument(s): "The given path format is not supported."
No line:1 character:1
+ $linblk = [System.IO.File]::ReadAllText('C:\Users\$env:username\Deskt ...


+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

如何使命令接受变量$env:username?

已编辑:
所以它起作用了:答案中的命令@Vomit IT - Chunky Mess Style

$linblk = [System.IO.File]::ReadAllText("C:\Users\$($env:username)\Desktop\List.txt");
$linblk = $linblk.Trim();
[System.IO.File]::WriteAllText("C:\Users\$($env:username)\Desktop\List.txt", $linblk)
windows-10 powershell-5.0
  • 1 个回答
  • 135 Views
Martin Hope
Clamarc
Asked: 2022-05-12 04:25:25 +0800 CST

将括号更改为文件名中的括号

  • 6

我需要递归地将音频文件名称中的方括号更改为多个文件夹中的括号。

原名:
Gonna Get Along Without You Now [Strelka Sounds Edit].mp3

我试过了:

ls $location* -Recurse -Include *.mp3 | Rename-Item -NewName {$_.name -Replace '[\[\]]', '('}

结果是:
Gonna Get Along Without You Now (Strelka Sounds Edit(.mp3

期望的结果:
Gonna Get Along Without You Now (Strelka Sounds Edit).mp3

如何以正确的顺序制作括号?

windows-10 powershell-5.0
  • 1 个回答
  • 252 Views
Martin Hope
Clamarc
Asked: 2022-05-10 22:40:04 +0800 CST

重启powershell脚本

  • 5

我的脚本计算 PC 上的音频文件并检查输入中输入的驱动器是否是系统驱动器。如果是,则发送一条消息以返回或退出脚本。我创建了 :INI 和 :EXIT 段落,但脚本没有返回到 :INI?

脚本:

clear-Host
:INI
cls
Write-Host "                                          Count Audio Files on PC" -ForegroundColor Yellow
$br
$local= Read-Host -Prompt " Enter your path Music folder. Eg. D:\*"
$location = "$local"

$locTst = $location.substring(0,2)

# Check if the drive c:
If ($locTst -eq "c:") {
    write-host -ForegroundColor Red " Drive $locTst does not allow access to external scripts!"
    $dirLoc= Read-Host -Prompt " Return?(Y/N)"
    if ($dirLoc -eq "y") { 
       :INI
    } else {  
       :EXIT
    }
}

commands to counting audio files...

:EXIT
exit

如何使脚本返回到 :INI 以重新启动脚本,并且在 :EXIT 中关闭 powershell 屏幕?

我尝试使用此链接中的命令,但它们在 Powershell ISE 中出现错误,我无法调试代码。
我如何允许输入 y/n

windows-10 powershell
  • 1 个回答
  • 469 Views
Martin Hope
Clamarc
Asked: 2022-05-02 13:10:59 +0800 CST

如何清除 echo 命令发送的消息

  • 6

当输入的值错误时,我的批处理会通知用户,并提供两个选项:重新输入值或退出程序。

@echo off
cls
setlocal enabledelayedexpansion

set /p _Value=Enter the value:
for /f skip^=4 %%e in ('echo;prompt $E^|cmd')do set "_$E=%%e"

if "!_Value!" gtr "10" (
 echo %_$E%[31mInvalid value! Do you want to re-enter the value? (y=yes/n=exit) %_$E%[0m
 IF /i "!r!"=="y" goto RELOADSAMESCREEN 
 goto :eof
)

The only way I managed to make the message disappear when the retype option is chosen, was to reload the same screen because when the screen is reloaded, the CLS command clears the screen with the message and then loads the screen again, so the message disappears从屏幕上,用户可以重新输入值而不会出现错误消息。

如何清除 echo 命令发送的消息而无需重新加载同一屏幕?

已编辑:根据@iTwasnTme
答案更改了脚本,它好多了,但是输入字段在屏幕上不断重复,颜色不会变回白色。

修改后的脚本:

@echo off

setlocal enabledelayedexpansion
for /f skip^=4 %%e in ('echo;prompt $E^|cmd')do set "_$E=%%e"

:RELOADSAMESCREEN
color & echo\& set /p "_Value=Enter the value: "

if !_Value! gtr 10 =;(
     set /p "r=!_$E![31mInvalid value^!! Do you want to re-enter the value? [y=yes |or| n=exit] "
     if /i "!r!"=="y" (set /p "'=!_$E![1F!_$E![0J!_$E![1F" <nul & goto RELOADSAMESCREEN)
     color & set /p "'=!_$E![1F" <nul & endlocal & goto :eof
    );=

屏幕: 在此处输入图像描述

windows-10 batch-file
  • 1 个回答
  • 198 Views
Martin Hope
Clamarc
Asked: 2022-05-01 12:39:57 +0800 CST

使用 List.txt 文件将音频文件从多个子文件夹复制到另一个文件夹

  • 6

我的 Powershell 版本是 5.1.19041.1645

我想使用 txt 文件将音频文件从多个文件夹复制到另一个文件夹,其中 List.txt 文件中的歌曲名称与原始文件夹中的歌曲名称具有不同的结构。

我以链接为例:
search-and-copy-files-from-a-directory

我试过了:

$files = 'C:\Users\CMG\Desktop\List.txt'
$location = 'C:\Users\CMG\Desktop\Select Dance\'
$destination = 'C:\Users\CMG\Desktop\Select Dance Copy\'

Get-ChildItem $location -Filter *.mp3 |
Foreach-Object {  
  $content = $_.Name
  $pos = $content.IndexOf("-")
  $artistPart = $content.Substring(0, $pos)
  $musicPart = $content.Substring($pos+2)

  $pos2 = $musicPart.IndexOf(".")
  $musileft = $musicPart.Substring(0, $pos2)

  If ($pos2 -lt 36) {
    $leng=$pos2
  } else {
    $leng=$pos2-($pos2-36)
  } 

  $musicNameRight = $musileft.Substring(0, $leng)  
}     
gc $files | % {
                   
    $result = gci -Recurse $location$musicNameRight $_
            
    if($result) {
        write-host -ForegroundColor Green "found $_ in $location!"
        write-host "copying $_ to $destination..."
        copy-item $result.FullName $destination\$_
    }
}

在 Foreach-Object 中,我设法从原始名称 ($location) 中消除了不同的部分,Artist Name - 并且.mp3从 List.txt ($files) 中的名称中消除了,但我无法获取脚本来比较文件使用来自$musicNameRight变量的信息。

“$files”路径中包含的歌曲名称:
Good Times (Dj 'S' Bootleg CMG Dance

“$location”路径中包含的歌曲名称:
Chic - Good Times (Dj 'S' Bootleg CMG Dance Re Mix).mp3

如何使脚本使用变量中名称的正确信息$musicNameRight?

注意:
我定义$musicPart.Substring(0, 36)了 ,因为 List.txt 文件中的所有歌曲名称都限制为 36 个字符。他们永远不会拥有更多。

windows powershell-5.0
  • 1 个回答
  • 366 Views
Martin Hope
Clamarc
Asked: 2022-04-29 23:22:27 +0800 CST

选择命令仅在 if 的嵌套中返回 errorelevel=0

  • 5

我在 IF 的嵌套中执行调用选择命令,但它只返回“errorlevel=0”。当我用完 if 时,它可以正常工作并在我选择 y=yes 时返回值 1。

我使用了链接中显示的命令:
正确使用选择内部调用功能

命令代码:

if "%opm%"=="1" (
 if "%sel%"=="out" (
  for /f skip^=4 %%e in ('echo;prompt $E^|cmd') do (set "_$E=%%e")
  set /p "'=%_$E%[31mThere are no files in the folder! Do you want to search another file? %_$E%[31m" <nul
  call choice /n /m "(y=yes/n=no)" 
  if "%errorlevel%"=="1" (
   goto anotherfile
  )else (
   endlocal & goto notfound
  )
 )
)

无论我选择哪个选项都会返回 errorlevel=0。

windows-10 batch-file
  • 1 个回答
  • 170 Views
Martin Hope
Clamarc
Asked: 2022-04-25 22:23:35 +0800 CST

检查具有负十进制值的字符串是否包含特殊字符

  • 6

我需要检查具有负值的字符串是否包含特殊字符。当我键入 -7.!、-7.@、-7.# 时,发现特殊字符,发送错误消息并关闭程序,但是当我键入有效值时,例如。-7.1, -7.5 发送错误信息,程序也关闭。

我尝试了在链接中找到的命令:
check-string-contains-special-characters

我试过这个:

set /p "_vLUF=Valor LUFS: "
echo;!_vLUF!|findstr /r "[%% # & ^ @ $ ~ !]" >nul && echo Invalid Value goto exit

如何使用相同的 findstr 命令检查字符串,从而避免在以下规则中使用多个 IF。

注意:不是在单个 findstr 中,而是使用 findstr 命令。

该字符串只能包含:

- negative values;
- have more than 3 digits;
- numeric characters;
- only 1 decimal value (eg. -9.00, -7.01 are not allowed);
- numbers starting without 0 (eg. -010.0, -09.0 are not allowed);
- be between the values -9.0 to -0.0. (eg. -9.1 and 0.1 are not allowed)
windows-10 string-manipulation
  • 1 个回答
  • 100 Views
Martin Hope
Clamarc
Asked: 2022-04-18 15:08:33 +0800 CST

带有负变量的 if 语句

  • 5

我的输入变量只包含负值,-5.0,-10.0... 将由 IF 语句检查。当变量小于 -5.0 时,例如。-4.9, -3.0,... 将发送无效值消息。

为了避免涉及到负号的比较,我统计了变量的字符来得到不带符号的变量的值,见下图:

我使用此链接来使用变量中的字符数:
Count variable characters with negative value

第一个变量:

set /p _vLUF=LUFS value: -5.0
echo vLUF: %vLUF%
vLUF: -5.0

第二个变量:

set /p _vLUF=LUFS value: -10.0
echo vLUF: %vLUF%
vLUF: -10.0

计算变量的字符:

setlocal enabledelayedexpansion
for %%i in (v)do set _cnt_%%~i=<nul
for /f delims^=^ eol^= %%G in ('"cmd.exe /u /c echo=!_vLUF!|find/v """')do set /a "_cnt_vLUF+=1+0"

First variable: has 4 characters
Second variable: has 5 characters

从变量中删除符号:

If !_cnt_vLUF!==4 (
 set positive=%_vLUF:~1.3%
)ELSE (
 set positive=%_vLUF:~1.4%
)

echo first variable: !positive!
first variable: 5.0

echo second variable: !positive!
second variable: 10.0

if 语句发送警告信息:

If "!positive!" lss "5.0" (
  SETLOCAL EnableExtensions DisableDelayedExpansion
  echo %ESC%[31mInvalid LUFS Value! Valid values:%ESC%[32m
  -70.0 to -5.0%ESC%[0m%ESC%[31m.%ESC%[0m%ESC%
  [31mReturn? (y=yes/enter=exit^) %ESC%[0m
  SETLOCAL EnableDelayedExpansion
  set /p r=""
  IF /i "!r!"=="s" goto SETLUFSPEAK
  goto notfound
)
endlocal

只要变量的值在 0.0 到 9.9 之间,If 语句就可以正常工作,例如:

3.0 invalid value message
4.9 Invalid value message
5.0 process without error message
9.9 process without error message

但是当值变为 10.0 时,IF 语句认为值 10.0 小于 5.0 并在它应该处理记录时发出错误消息。

windows-10 batch
  • 2 个回答
  • 116 Views
Martin Hope
Clamarc
Asked: 2022-04-17 23:35:21 +0800 CST

计算具有负值的变量字符

  • 7

我在批处理文件中有一个带有负数 -5.0 的变量 (vLUF),我需要获取它具有的字符数。我正在使用上面链接上发布的命令,但变量“count”返回没有值。

如何计算文本文件中的字符数

显示输入变量:

echo input variable %vLUF%
input variable -5.0

突击队:

for %i in (%vLUF%) do @set count=%~zi

echo %count%  
%count%

我将变量更改为 5.0, 50, abc,... 但计数器不返回任何内容。

windows-10 command-line
  • 2 个回答
  • 366 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve