Get full path of the files in PowerShell

后端 未结 14 2112
挽巷
挽巷 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:02

    [alternative syntax]

    For some people, directional pipe operators are not their taste, but they rather prefer chaining. See some interesting opinions on this topic shared in roslyn issue tracker: dotnet/roslyn#5445.

    Based on the case and the context, one of this approach can be considered implicit (or indirect). For example, in this case using pipe against enumerable requires special token $_ (aka PowerShell's "THIS" token) might appear distasteful to some.

    For such fellas, here is a more concise, straight-forward way of doing it with dot chaining:

    (gci . -re -fi *.txt).FullName
    

    (<rant> Note that PowerShell's command arguments parser accepts the partial parameter names. So in addition to -recursive; -recursiv, -recursi, -recurs, -recur, -recu, -rec and -re are accepted, but unfortunately not -r .. which is the only correct choice that makes sense with single - character (if we go by POSIXy UNIXy conventions)! </rant>)

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

    Here's a shorter one:

    (Get-ChildItem C:\MYDIRECTORY -Recurse).fullname > filename.txt
    
    0 讨论(0)
  • 2020-12-02 07:09

    If relative paths are what you want you can just use the -Name flag.

    Get-ChildItem "C:\windows\System32" -Recurse -Filter *.txt -Name

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

    This worked for me, and produces a list of names:

    $Thisfile=(get-childitem -path 10* -include '*.JPG' -recurse).fullname
    

    I found it by using get-member -membertype properties, an incredibly useful command. most of the options it gives you are appended with a .<thing>, like fullname is here. You can stick the same command;

      | get-member -membertype properties 
    

    at the end of any command to get more information on the things you can do with them and how to access those:

    get-childitem -path 10* -include '*.JPG' -recurse | get-member -membertype properties
    
    0 讨论(0)
  • 2020-12-02 07:14

    I am using below script to extact all folder path:

    Get-ChildItem -path "C:\" -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName | Out-File "Folder_List.csv"
    

    Full folder path is not coming. After 113 characters, is coming:

    Example - C:\ProgramData\Microsoft\Windows\DeviceMetadataCache\dmrccache\en-US\ec4d5fdd-aa12-400f-83e2-7b0ea6023eb7\Windows...
    
    0 讨论(0)
  • 2020-12-02 07:14

    I used this line command to search ".xlm" files in "C:\Temp" and the result print fullname path in file "result.txt":

    (Get-ChildItem "C:\Temp" -Recurse | where {$_.extension -eq ".xml"} ).fullname > result.txt 
    

    In my tests, this syntax works beautiful for me.

    0 讨论(0)
提交回复
热议问题