In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In our daily work, we often need to export the current shared environment or disk file directory hierarchy, etc. At the earliest, when there are few directories, we can clearly see the directory and file hierarchy by using the tree command under CMD, so how do we intuitively display or export a file directory or drive directory hierarchy through powershell?
View directory and file structure under DOS:
Tree /?
Graphically displays the folder structure of the drive or path.
TREE [drive:] [path] [/ F] [/ A]
/ F displays the name of the file in each folder.
/ A uses ASCII characters instead of extended characters.
Powershell to view directories and file structures:
In fact, we can also use the powershell command with the tree command. The simple operation is as follows:
Get-ChildItem D:\ SW_Office_Plus | tree / f
Get-ChildItem D:\ SW_Office_Plus | tree / A
Get-ChildItem: gets items and subitems in one or more specified locations.
Get the folder name under the current directory:
Get-ChildItem D:\ SW_Office_Plus |? {$_ .psiscontainer-eq $true}
Get the file name under the current directory:
Get-ChildItem D:\ SW_Office_Plus |? {$_ .psiscontainer-eq $false}
Next, let's move on to today's topic, how to view the file level under the current directory. The specific commands are as follows:
Get-ChildItem-Recurse-Directory-Depth 3 | select FullName
Get-ChildItem D:\ SW_Office_Plus-Recurse-Directory-Depth 3 | select Fullname
If you need to export the results, you can do so with the following command:
Get-ChildItem-Recurse-Directory-Depth 3 | select FullName | Export-Csv d:\ fullname.csv-Encoding UTF8-NoTypeInformation
PS. Add: export file, file directory name, creation time, format and other information:
Get-ChildItem-Path D:\ SW_Office_Plus-Recurse | `foreach {$Item = $_ $Type = $_. Extension$Path = $_. FullName$ParentS = ($_ .Fullname) .split ("\") $Parent = $ParentS [@ ($ParentS.Length-2)] $ParentPath = $_. PSParentPath$ParentPathSplit = ($_ .PSParentPath) .split (":") $ParentPathFinal = $ParentPathSplit [@ ($ParentPathSplit.Length-1)] # $ParentPath = [io.path]: GetDirectoryName ($myDirectory) $Folder = $_. PSIsContainer$Age = $_. CreationTime$Path | Select-Object `@ n = "Name" E = {$Item}}, `@ {n = "Created"; e = {$Age}},` @ {n = "Folder Name"; e = {if ($Parent) {$Parent} else {$Parent}}, `@ {n = "filePath"; e = {$Path}},` @ {n = "Extension"; e = {if ($Folder) {"Folder"} else {$Type}}, `@ {n = "Folder Name 2" E = {if ($Parent) {$Parent} else {$Parent}}, `# @ {n = "Folder Path"; e = {$ParentPath}},` @ {n = "Folder Path 2"; e = {$ParentPathFinal} `} | Export-Csv d:\ Folder.csv-Encoding UTF8-NoTypeInformation
The format after export is as follows, which can be filtered by yourself. For more information on the content of the script, please refer to the link.
Welcome to the official account of Wechat: Xiao Wen study Society.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.