dir10 | |-> dir20 |...">

"get-childitem * -recurse" discards first-level directories

Suppose we have the following directory structure:

~dir00
   |-> dir10
   |     |-> dir20
   |           |-> file1.txt
   |-> dir11
         |-> file2.txt

Now suppose ~ dir00 is the current directory. I would expect that the two teams
get-childitem * -recurse
and
get-childitem -recurse
to obtain the same results. However, they do not. The behavior of the second is what I expect.

I am trying to write a small library of tools for use with our scripts. One tool I need to write is a tool for copying and backing up filesets. I get as input what tells me which files / directories / etc. copy. I do not know what the user can provide. They can provide wild-cards, such as "*", they can provide a file name, they can provide a -recurse option, etc. Etc. Inputs are served by get-childitem. The inconsistency of get-childitem behavior when the "path" is just "*" is a big problem. Why does get-childitem suddenly drop first-level directories when they feed "-path" from "*" and the -recurse option? (Note that it only drops first-level directories.) ?

bizzare. ,

~dir00
   |-> dir10
   |     |-> dir20
   |           |-> file1.txt
   |-> dir11
   |     |-> file2.txt
   |-> file3.txt

. , script:

cd $Env:temp
mkdir dir00\dir10\dir20 | out-null
cd dir00
mkdir dir11 | out-null
echo 'hello world 1'>dir10\dir20\file1.txt
echo 'hello world 2'>dir11\file2.txt
$list1 = get-childitem -recurse
echo 'Results of get-childitem -recurse: '
$list1
echo ''
echo 'Number of items:'
$list1.length
echo ''
$list2 = get-childitem * -recurse
echo 'Results of get-childitem * -recurse: '
$list2
echo ''
echo 'Number of items:'
$list2.length
echo ''
echo "hello world 3">file3.txt
$list3 = get-childitem * -recurse
echo 'Results of get-childitem * -recurse: '
$list3
echo ''
echo 'Number of items:'
$list3.length
echo ''
+4
2

, CMDLet Get-ChildItem . - :

$suppliedPath = "*"
if($suppliedPath -eq "*"){
    $suppliedPath = $suppliedPath.replace("*", ".")
}
Get-ChildItem $suppliedPath -recurse
+1

, , Get-ChildItem, .

:

Get-ChildItem -Recurse

, :

Get-ChildItem -Path . -Recurse

: -Path (dir00)

:

Get-ChildItem * -Recurse

, *, , Get-ChildItme, . , :

$items = Get-ChildItem *
Get-ChildItem $items -Recurse

:

Get-ChildItem -Path ./dir10 -Recurse
Get-ChildItem -Path ./dir11 -Recurse

, , ( ) , , , . dir00:

echo 'hello world 1'>test1.txt

Get-ChildItem * -Recurse

, Get-ChildItem -Recurse. , , , .

+6

All Articles