Asked by:
GetChildItem and its -File option

Question
-
I have Powershell version 5.1.16299.248 and I am learning Powershell,
I would like to know, in details, what the '-File' option used with 'GetChildItem', for example, does. Does it only keep non-directory files or does it do something more?
I know it is a kind-of-useless question, but I am interested in the answer.
Thanks,
-Jean-Claude
Sunday, February 18, 2018 11:55 PM
All replies
-
Hi Jean Claude,
Please see the official documentation of the cmdlet https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6
To get only files, use the
-File
parameter and omit the Directory parameter.Regards
Simon
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. Regards Simon Disclaimer: This posting is provided AS IS with no warranties or guarantees, and confers no rights.
- Proposed as answer by Albert LingMicrosoft contingent staff Monday, February 19, 2018 11:24 AM
Monday, February 19, 2018 12:04 AM -
Hi Simon,
Thank you for your link, but what I am looking for is rather an explanation of what is a file in the context of the 'GetChildItem' command, when saying a 'file' does it mean 'non-directory' (so, anything that is not a directory), which is what I understand, or is there something more to the definition of 'file'
Thanks,
Jean-Claude
Monday, February 19, 2018 12:10 AM -
Dear Jean-Claude,
If you use get-childitem -file it will list only files (not folders). You can use the -file also to list files with a certain extension for example:
get-childitem -file *.tmp
Will list only the files with extension .tmp
Regards
Simon
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. Regards Simon Disclaimer: This posting is provided AS IS with no warranties or guarantees, and confers no rights.
Monday, February 19, 2018 12:21 AM -
I have Powershell version 5.1.16299.248 and I am learning Powershell,
I would like to know, in details, what the '-File' option used with 'GetChildItem', for example, does. Does it only keep non-directory files or does it do something more?
I know it is a kind-of-useless question, but I am interested in the answer.
Thanks,
-Jean-Claude
I recommend that, before you try to learn PowerShell, you learn basic Windows and the Windows file system. With a good basic technical knowledge of Windows you will not be able to learn or use PowerShell.\_(ツ)_/
Monday, February 19, 2018 7:17 AM