Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 Get ChildItem-Recurse在提供正则表达式模式时不递归搜索_Powershell - Fatal编程技术网

Powershell Get ChildItem-Recurse在提供正则表达式模式时不递归搜索

Powershell Get ChildItem-Recurse在提供正则表达式模式时不递归搜索,powershell,Powershell,上一个开发人员有一个系统,可以复制shadow中的每个文件。\ u FILENAME,它占用的空间是项目中原始文件的两倍 例如: ._index.php 500kb ._menu.php 600kb index.php 250kb menu.php 300kb 我正在尝试制作一个小脚本来删除所有的。\ u FILENAME,但它看起来只是扫描活动文件夹,而不是递归地进入所有子文件夹 Get-ChildItem -Path . -File -Include * -Recurse | Where

上一个开发人员有一个系统,可以复制shadow中的每个文件。\ u FILENAME,它占用的空间是项目中原始文件的两倍

例如:

._index.php 500kb
._menu.php 600kb
index.php 250kb
menu.php 300kb
我正在尝试制作一个小脚本来删除所有的。\ u FILENAME,但它看起来只是扫描活动文件夹,而不是递归地进入所有子文件夹

Get-ChildItem -Path . -File -Include * -Recurse  | Where-Object { $_.Name -match '^\._.*$' } | foreach { echo "Deleting: $_"}

我发现如何通过在递归之后添加-Force来实现我的需求。我仍然不知道为什么,这对我来说是一种奇怪的行为

Get-ChildItem -Path . -Include * -Recurse -Force | Where-Object { $_.Name -match '^\._.*$' } | foreach { echo "Deleting: $_"  ; $_.Delete() } | Out-File deleted.txt

我添加了文件deleted.txt,所以它会将所有内容输出到一个文本文件中,这样我可以在操作后参考它

如果在没有Where对象的情况下使用Get-ChildItem-Path$currentfolder-File-Include*-Recurse,那么Get-ChildItem-Path$currentfolder-File-Include*-Recurse是否正常工作?是的,它返回所有内容,如果您这样编写:$AllResults=Get-ChildItem-Path$currentfolder-File-Include*-rec$FilteredResults=$AllResults |其中对象{$\.Name-match'^\...*$'}?$AllResults、$FilteredResults是否包含子文件夹结果?文件是否隐藏?如果您添加-Hidden作为参数来获取ChildItem会怎么样?我尝试复制它,它按预期工作。我假设$currentfolder不包含预期的路径!?