Get-ChildItem -Recurse does not return recursively

1

I am trying to create a script in powershell to manipulate the files of a directory, however when using the parameter -Recurse I have not got the items of the subfolders

    # onde $source = C:\Files
    # e dentro de Files tem mais duas pastas 001 e 002 com arquivos dentros
    Get-ChildItem -Path $source -Recurse -Filter * |
    ForEach-Object {

        #Recupera a data atual da movimentação
        $date = (Get-Date).ToString();

        #Adiciona conteúdo ao arquivo $log com a data atual da movimentação
        Add-Content -Path $log " $date - O arquivo $_ foi transferido de $source para $target";

        #Escreve em tela
        Write-Host " $date - O arquivo $_ foi transferido de $source para $target";

        #Realiza a copia dos itens
        Move-Item $_.FullName $target;
    }

    
asked by anonymous 29.10.2015 / 19:28

1 answer

1
Get-ChildItem -Path $source -Recurse -Filter * | 
Where-Object { -not $_.PSIsContainer } |
    ForEach-Object {

        # Get the current date
        $date = (Get-Date).ToString();

        # Add to log file
        Add-Content -Path $log " $date - The file $_ was moved from $source to $target";

        # Show on cmdlet
        Write-Host " $date - O arquivo $_ foi transferido de $source para $target";

        # Move items
        Move-Item $_.FullName $target;
    }

The .PSIsContainer property returns true when the item is a container (a directory).

In PowerShell v3 and above can be used as follows:

Get-ChildItem -Path $Source -Directory -Recurse -Filter *

SOEN Response Link

    
29.10.2015 / 19:59