如何在 CLI 界面 (PowerShell) 中 select 多个文件
How can I select multiple files in a CLI interface (PowerShell)
我正在尝试将一些 gif 文件批量转换为动画 png 文件,但是,我的问题很明确。如何将目录中的多个文件输入到 CLI 终端(我使用的是 PowerShell)?
我是一个新手,所以我 99% 确定我在做一些愚蠢的事情。
我正在使用 gif 到动画 png 程序 (gif2apng)
当我输入
之类的东西时,它工作得很好
gif2apng -i file.gif -o output.png
我在该目录中有多个 GIF,因此,我使用了通配符
gif2apng -i *.gif
但是,我得到一个错误
Error: can't open the file '*.gif'
当我尝试 select 多个图像(使用 Google 的程序,img2webp)时,我得到了这个确切的错误,而不是像这样写所有的名字
img2webp -lossy 1.png 2.png 3.png 4.png 5.png 6.png -o output.png
只需写
img2webp -lossy *.png
请指导我
谢谢,
刺耳
与 POSIX 兼容的 shell(例如类 Unix 平台上的 bash
)不同,PowerShell 在 Windows[1] not 执行 globbing - 也就是说,它 not 自动扩展 *.gif
到名称当前目录中扩展名为 .gif
的文件数
因此,通配模式 *.gif
被 逐字 传递给 gif2apng
,这似乎需要 文字 文件名和因此失败。
解决方案是让 PowerShell 使用 Get-ChildItem
cmdlet 显式 执行通配:
gif2apng -i (Get-ChildItem *.gif).Name -o output.png
Get-ChildItem *.gif
检索当前目录中扩展名为 .gif
的所有项目(如果您明确想从匹配中排除 directories,您可以添加 -File
开关)作为 System.IO.FileInfo
个实例。
(...).Name
returns 他们的名字并将他们作为 个人参数 传递给 gif2apng
.
[1] 但是,在类 Unix 平台上(macOS,Linux)PowerShell(Core} 7+ 是否为 外部程序.
执行此自动 globbing
我正在尝试将一些 gif 文件批量转换为动画 png 文件,但是,我的问题很明确。如何将目录中的多个文件输入到 CLI 终端(我使用的是 PowerShell)?
我是一个新手,所以我 99% 确定我在做一些愚蠢的事情。
我正在使用 gif 到动画 png 程序 (gif2apng) 当我输入
之类的东西时,它工作得很好gif2apng -i file.gif -o output.png
我在该目录中有多个 GIF,因此,我使用了通配符
gif2apng -i *.gif
但是,我得到一个错误
Error: can't open the file '*.gif'
当我尝试 select 多个图像(使用 Google 的程序,img2webp)时,我得到了这个确切的错误,而不是像这样写所有的名字
img2webp -lossy 1.png 2.png 3.png 4.png 5.png 6.png -o output.png
只需写
img2webp -lossy *.png
请指导我
谢谢, 刺耳
与 POSIX 兼容的 shell(例如类 Unix 平台上的 bash
)不同,PowerShell 在 Windows[1] not 执行 globbing - 也就是说,它 not 自动扩展 *.gif
到名称当前目录中扩展名为 .gif
因此,通配模式 *.gif
被 逐字 传递给 gif2apng
,这似乎需要 文字 文件名和因此失败。
解决方案是让 PowerShell 使用 Get-ChildItem
cmdlet 显式 执行通配:
gif2apng -i (Get-ChildItem *.gif).Name -o output.png
Get-ChildItem *.gif
检索当前目录中扩展名为.gif
的所有项目(如果您明确想从匹配中排除 directories,您可以添加-File
开关)作为System.IO.FileInfo
个实例。(...).Name
returns 他们的名字并将他们作为 个人参数 传递给gif2apng
.
[1] 但是,在类 Unix 平台上(macOS,Linux)PowerShell(Core} 7+ 是否为 外部程序.
执行此自动 globbing