none
Using Get-ChildItem to list only file (and not folder) names RRS feed

  • Question

  • Hello,

    I am running the following PS command:

    Get-ChildItem A:\u_W\u_L\c_Psns\ -name -include *_CV_z.pdf -recurse > A:\u_W\u_OutputLocation.txt

    I am getting the following output:

    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_YiakJ00_zzzzzzz_n_e_f_CV_z.pdf

    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_ZamaM00_zzzzzzz_n_e_f_CV_z.pdf

    u_BurvJ00\u_zzzzzzzz_zzzzzzzz_zzzzzzzz_BurvJ00_zzzzzzz_n_e_f_CV_z.pdf

    u_ButJA00\u_zzzzzzzz_zzzzzzzz_zzzzzzzz_ButJA00_zzzzzzz_n_e_f_CV_z.pdf

    However, my goal is to get the following output:
    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_YiakJ00_zzzzzzz_n_e_f_CV_z.pdf
    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_ZamaM00_zzzzzzz_n_e_f_CV_z.pdf
    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_BurvJ00_zzzzzzz_n_e_f_CV_z.pdf
    u_zzzzzzzz_zzzzzzzz_zzzzzzzz_ButJA00_zzzzzzz_n_e_f_CV_z.pdf
    In other words, I do not want folder names in the output; I just want file names. I would have thought that the -name parameter achieves this, but it does not seem to.
    Thanks.
    Keith

    Monday, November 7, 2011 2:50 PM

Answers

  • Get-ChildItem A:\u_W\u_L\c_Psns\  -include *_CV_z.pdf -recurse | Select -exp Name > A:\u_W\u_OutputLocation.txt
    


    • Edited by Kazun Monday, November 7, 2011 2:57 PM
    • Proposed as answer by Bigteddy Monday, November 7, 2011 3:04 PM
    • Marked as answer by Tiger LiMicrosoft employee Monday, November 14, 2011 1:53 AM
    Monday, November 7, 2011 2:57 PM
  • Hello Kazun,

    That's a good clue, but I cannot quite get it to work.

    When I run the following command, PowerShell complains that it cannot recognise the final "Name".

    Get-ChildItem A:\u_W\u_L\c_Psns\ -name -include *_CV_z.pdf -recurse | Select-Object Name

    Is there a way to get a list of the possible items that can be selected (i.e., instead of Name)?

    Many thanks.

    Keith

    You incorrect copy a command.

    Get-ChildItem A:\u_W\u_L\c_Psns\  -include *_CV_z.pdf -recurse | Select -exp Name
    

    Monday, November 7, 2011 8:20 PM

All replies

  • Get-ChildItem A:\u_W\u_L\c_Psns\  -include *_CV_z.pdf -recurse | Select -exp Name > A:\u_W\u_OutputLocation.txt
    


    • Edited by Kazun Monday, November 7, 2011 2:57 PM
    • Proposed as answer by Bigteddy Monday, November 7, 2011 3:04 PM
    • Marked as answer by Tiger LiMicrosoft employee Monday, November 14, 2011 1:53 AM
    Monday, November 7, 2011 2:57 PM
  • Hello Kazun,

    That's a good clue, but I cannot quite get it to work.

    When I run the following command, PowerShell complains that it cannot recognise the final "Name".

    Get-ChildItem A:\u_W\u_L\c_Psns\ -name -include *_CV_z.pdf -recurse | Select-Object Name

    Is there a way to get a list of the possible items that can be selected (i.e., instead of Name)?

    Many thanks.

    Keith

    Monday, November 7, 2011 8:14 PM
  • Hello Kazun,

    That's a good clue, but I cannot quite get it to work.

    When I run the following command, PowerShell complains that it cannot recognise the final "Name".

    Get-ChildItem A:\u_W\u_L\c_Psns\ -name -include *_CV_z.pdf -recurse | Select-Object Name

    Is there a way to get a list of the possible items that can be selected (i.e., instead of Name)?

    Many thanks.

    Keith

    You incorrect copy a command.

    Get-ChildItem A:\u_W\u_L\c_Psns\  -include *_CV_z.pdf -recurse | Select -exp Name
    

    Monday, November 7, 2011 8:20 PM
  • Hello Kazun,

    My mistake. I typed your suggestion, and it works.

    Also, I looked up the "exp" option for the Select commandlet, and I understand that it stands for "ExpandProperty".

    Thanks for your help.

    Keith


    R K Howard
    Thursday, November 17, 2011 2:10 PM
  • A better way to do it is to check for PsIsContainer property of objects returned from Get-ChildItem.

    Refer to http://gunnalag.com/2013/05/09/powershell-list-only-files-andor-folders/ for detailed examples.


    You are the Knowledge You have…
    MyWordPress; MyBlogSpot; MyMicrosoft; MyCitrix;
    MyVMWare; MySymantec; MyLinkedIn; MyFaceBook; MyGReader;

    Thursday, May 9, 2013 3:42 PM