Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powershell可以进行文件名扩展吗?_Powershell - Fatal编程技术网

powershell可以进行文件名扩展吗?

powershell可以进行文件名扩展吗?,powershell,Powershell,在unix shell中,类似以下命令的命令: echo *.txt 印刷品: 1.txt 2.txt 3.txt 因为shell在*.txtarg上执行文件名扩展。使用Powershell是否可以达到相同的效果?尝试: echo *.txt 结果如下: *.txt 当然,echo只是一个愚蠢的例子。实际上,我希望将所有*.txt文件传递给一个本身不执行文件名扩展的外部命令 更新 就我而言,这是看起来最好的,尽管它不是很优雅: D:\cygwin\bin\echo.exe $(dir *

在unix shell中,类似以下命令的命令:

echo *.txt
印刷品:

1.txt 2.txt 3.txt
因为shell在
*.txt
arg上执行文件名扩展。使用Powershell是否可以达到相同的效果?尝试:

echo *.txt
结果如下:

*.txt
当然,echo只是一个愚蠢的例子。实际上,我希望将所有*.txt文件传递给一个本身不执行文件名扩展的外部命令

更新 就我而言,这是看起来最好的,尽管它不是很优雅:

D:\cygwin\bin\echo.exe $(dir *.txt)

我在这里使用cygwin echo进行测试,因为powershell echo cmdlet将文件格式化为对象。

您可以这样做。该命令不像bash那样简洁,但其思想是相同的。试着这样做:

Get-ChildItem -Filter "*.txt"


你可以这样做。该命令不像bash那样简洁,但其思想是相同的。试着这样做:

Get-ChildItem -Filter "*.txt"


我会使用
Get ChildItem*.txt-name
或使用别名
ls*.txt-name
。如果您希望文件名位于同一行,那么我在中添加了
“$(ls*.ps1-name)”
@KeithHill。但我通常不喜欢使用PS别名。不要忘记该语句周围的双引号。这是从子表达式返回的数组中创建字符串的重要位。默认分隔符是空格,但您可以使用
$OFS
变量更改此分隔符。设置
$OFS=”,“
然后运行
“$(Get ChildItem*.txt-Name)”
您将得到逗号分隔的名称。我将使用
Get ChildItem*.txt-Name
或使用别名
ls*.txt-Name
。如果您希望文件名位于同一行,那么我在中添加了
“$(ls*.ps1-name)”
@KeithHill。但我通常不喜欢使用PS别名。不要忘记该语句周围的双引号。这是从子表达式返回的数组中创建字符串的重要位。默认分隔符是空格,但您可以使用
$OFS
变量更改此分隔符。设置
$OFS=','
然后运行
“$(Get ChildItem*.txt-Name)”
将获得逗号分隔的名称。
"$(Get-ChildItem *.txt -Name)"