This article describes a PowerShell use of the Get-childitem cmdlet to get a list of files in a directory. Get-childitem is the meaning of getting subprojects, and you can get files and subdirectories in a directory.
Under the DOS system, we want to see which subdirectories and files are in a directory, and we can do that with the dir command. In PowerShell, the dir command appears to be still available. But Hongo tells you, this dir is not the dir in Cmd.exe, it is Get-childitem this cmdlet alias. That is to say, using Get-childitem and using Dir are exactly the same effect.
Let's look at how Get-childitem is used in PowerShell.
1, view the Sub folder and file list under D disk
Copy Code code as follows:
PS c:\users\splaybow> Get-childitem D:\
Table of Contents: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
D----2013/11/15 10:50 develop
D----2013/11/1 22:27 Green
D----2013/11/4 17:31 program Files
D----2013/11/17 9:30 program Files (x86)
D----2013/10/13 10:02 soft
Of course, Hongo D does not put the file directly, so just look at some directories.
2. View all txt suffix files under D disk
Copy Code code as follows:
PS c:\users\splaybow> get-childitem d:\-include *.txt-recurse
Table of Contents: D:\develop\tomcat8\webapps\docs\appdev\sample\docs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-----2013/10/16 14:50 857 README.txt
Table of Contents: D:\develop\tomcat8\webapps\docs\appdev
Mode LastWriteTime Length Name
---- ------------- ------ ----
-----2013/10/16 14:50 17262 build.xml.txt
-----2013/10/16 14:50 6421 web.xml.txt
There is a lot of content under the file list, and Hongo is not listed. In Get-childitem This cmdlet,-recurse indicates whether to iterate through subdirectories, while-include represents filter criteria.
3, view the file under D disk list, do not display the directory
Copy Code code as follows:
PS c:\users\splaybow> echo "xxx" >d:\1.txt
PS c:\users\splaybow> Get-childitem D:\
Table of Contents: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
D----2013/11/15 10:50 develop
D----2013/11/1 22:27 Green
D----2013/11/4 17:31 program Files
D----2013/11/17 9:30 program Files (x86)
D----2013/10/13 10:02 soft
-A---2013/11/17 19:07 1.txt
PS c:\users\splaybow> Get-childitem D:\ | ? {$_. Psiscontainer-eq $false}
Table of Contents: D:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
-A---2013/11/17 19:07 1.txt
In the above command, Hongo first uses echo to create a 1.txt under D:\. When you use Get-childitem, you can see that there are 1.txt items in the file list, and of course there are other directories. Finally, Hongo uses a pipe command to filter items that are not directories from the file list, and gets a 1.txt file list.
Finally, Get-childitem can be used to display not only the file list of file systems, but also the tree-like paths of environment variables (env), Registry (HKLM), Certificates (cert), variables (Variable).
About PowerShell using Get-childitem to get the list of files in the directory, this article on the introduction so much, I hope to help you, thank you!