Get full path of the files in PowerShell

后端 未结 14 2091
挽巷
挽巷 2020-12-02 06:21

I need to get all the files including the files present in the subfolders that belong to a particular type.

I am doing something like this, using Get-ChildItem:

相关标签:
14条回答
  • 2020-12-02 07:25
    Get-ChildItem -Recurse *.txt | Format-Table FullName
    

    That is what I used. I feel it is more understandable as it doesn't contain any loop syntax.

    0 讨论(0)
  • 2020-12-02 07:25

    Why has nobody used the foreach loop yet? A pro here is that you can easily name your variable:

    # Note that I'm pretty explicit here. This would work as well as the line after:
    # Get-ChildItem -Recurse C:\windows\System32\*.txt
    $fileList = Get-ChildItem -Recurse -Path C:\windows\System32 -Include *.txt
    foreach ($textfile in $fileList) {
        # This includes the filename ;)
        $filePath = $textfile.fullname
        # You can replace the next line with whatever you want to.
        Write-Output $filePath
    }
    
    0 讨论(0)
提交回复
热议问题