How can I list and print files in a directory?

I am trying to do this, but not printing anything:

Dir -Recurse "C:\temp" | Select Fullname

It looks like this command just selects the file names. I want to see them in the console.

+4
source share
3 answers

Take a look at Get-Childitem

Dir -Recurse c:\path\ | Get-Childitem
+2
source

Regarding your code in the question.

Your team should work as is. In fact, you are already calling Get-ChildItem. If you check Get-Alias, you will see what I'm trying to tell you.

PS C:\users\Cameron\Downloads> Get-Alias dir

CommandType     Name                                               ModuleName                                                                                               
-----------     ----                                               ----------                                                                                               
Alias           dir -> Get-ChildItem  

You translate the code into

Get-ChildItem -Recurse "C:\temp" | Select Fullname

, , , , . , ? PowerShell? ( Get-Host).

, , . , - ?

, , , Get-ChildItem

Dir -Recurse c:\path\ | Get-Childitem

C:\TEMP\TESTFile1.txtFile2.txt
└───Folder1
        File3.txt

, .

PS C:\users\Cameron\Downloads> Dir -Recurse c:\temp\test | Select Fullname

FullName                                                                                                                                                                    
--------                                                                                                                                                                    
C:\temp\test\Folder1                                                                                                                                                        
C:\temp\test\File1.txt                                                                                                                                                      
C:\temp\test\File2.txt                                                                                                                                                      
C:\temp\test\Folder1\File3.txt                                                                                                                                              



PS C:\users\Cameron\Downloads> Dir -Recurse c:\temp\test | Get-Childitem | Select Fullname

FullName                                                                                                                                                                    
--------                                                                                                                                                                    
C:\temp\test\Folder1\File3.txt                                                                                                                                              
C:\temp\test\File1.txt                                                                                                                                                      
C:\temp\test\File2.txt                                                                                                                                                      
C:\temp\test\Folder1\File3.txt   

File3.txt, .

+2

-force, .

0

Source: https://habr.com/ru/post/1569900/


All Articles