powershellcommand-linefile-listing

How to list file and folder names in powershell?


I want to write all files and folders' names into a .gitignore file like the below:

Folder1
Folder2
File1.bar
File2.foo

and so on.

The writing part can be achieved with the Out-File command, but I'm stuck in printing those names like the format above.

I'm aware of the command Get-ChildItem but it prints out a bunch of metadata like dates and icons too which are useless for the matter. btw, I'm looking for a single-line command, not a script.


Solution

  • Just print the Name property of the files like:

    $ (ls).Name >.gitignore
    

    or:

    $ (Get-ChildItem).Name | Out-File .gitignore