没有换行符的 powershell get-childitems
powershell get-childitems without newline
我喜欢将所有 *.csproj
文件放入我的文件夹(递归),然后将它们“tar”成一个 tar 球。我喜欢遵循 this 方法,但在 PowerShell 而不是 bash.
我已经想到的是:
gci -r -fi *.csproj | Resolve-Path -Relative | tar -cvf ball.tar --null -T -
现在的主要问题是,我得到了错误
Couldn't find file: No such file or directory
我认为这是因为与 bash
相比,PowerShell 在每个找到的条目末尾使用 NewLine
输出文件。
如何删除 NewLine
或避免首先添加它?
问题不在于 PowerShell,而是 tar
的 --null
选项的使用,它期望通过标准输入提供的文件路径是空字节而不是换行符分隔(后者是 PowerShell 使用的)。
只需省略 --null
即可:
gci -r -fi *.csproj | Resolve-Path -Relative | tar -cvf ball.tar -T -
或者 - 假设您没有 运行 进入具有大量匹配文件的命令行长度限制 - 您可以直接传递路径,依赖于 PowerShell 自动传递多个输出对象的能力调用外部程序时作为单独参数的表达式:
tar -cvf ball.tar (gci -r -fi *.csproj | Resolve-Path -Relative)
我喜欢将所有 *.csproj
文件放入我的文件夹(递归),然后将它们“tar”成一个 tar 球。我喜欢遵循 this 方法,但在 PowerShell 而不是 bash.
我已经想到的是:
gci -r -fi *.csproj | Resolve-Path -Relative | tar -cvf ball.tar --null -T -
现在的主要问题是,我得到了错误
Couldn't find file: No such file or directory
我认为这是因为与 bash
相比,PowerShell 在每个找到的条目末尾使用 NewLine
输出文件。
如何删除 NewLine
或避免首先添加它?
问题不在于 PowerShell,而是 tar
的 --null
选项的使用,它期望通过标准输入提供的文件路径是空字节而不是换行符分隔(后者是 PowerShell 使用的)。
只需省略 --null
即可:
gci -r -fi *.csproj | Resolve-Path -Relative | tar -cvf ball.tar -T -
或者 - 假设您没有 运行 进入具有大量匹配文件的命令行长度限制 - 您可以直接传递路径,依赖于 PowerShell 自动传递多个输出对象的能力调用外部程序时作为单独参数的表达式:
tar -cvf ball.tar (gci -r -fi *.csproj | Resolve-Path -Relative)