观察的名言,阳春市永宁镇,隐形眼镜亮视网
日常工作中我们往往有需要导出当前共享环境或磁盘文件目录层级结构等的需求,最早在目录少的情况下我们使用cmd下tree 命令可以很清晰的看到目录、文件层级结构,那么我们又如何通过powershell直观显示或导出某文件目录或盘符目录层级结构呢?
dos下查看目录、文件结构:
tree /?
以图形显示驱动器或路径的文件夹结构。
tree [drive:][path] [/f] [/a]
/f 显示每个文件夹中文件的名称。
/a 使用 ascii 字符,而不使用扩展字符。
powershell查看目录、文件结构:
其实我们通过powershell命令也可以搭配tree命令使用,简单操作如下:
get-childitem d:\sw_office_plus |tree /f
get-childitem d:\sw_office_plus |tree /a
get-childitem :获取一个或多个指定位置中的项和子项。
获取当前目录下文件夹名称:
get-childitem d:\sw_office_plus | ?{$_.psiscontainer -eq $true}
获取当前目录下文件名称:
get-childitem d:\sw_office_plus | ?{$_.psiscontainer -eq $false}
接下来进入我们今天的主题内容,如何查看当前目录下文件层级,具体命令如下:
get-childitem -recurse -directory -depth 3 |select fullname
get-childitem d:\sw_office_plus -recurse -directory -depth 3 |select fullname
如果需要对结果进行导出,可通过如下命令操作:
get-childitem -recurse -directory -depth 3 |select fullname | export-csv d:\fullname.csv -encoding utf8 –notypeinformation
ps.补充:导出文件、文件目录名称、创建时间、格式等等信息:
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
导出后格式如下,可自行筛选,该脚本内容具体可参考该。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新补丁让Windows 10出现死机、卡顿等 微软坐不住称正解决
Ubuntu 20.04 LTS进驻Windows子系统:只能用3年
ThinkPad正式加入:预装Linux发行版而非Win10的PC越来越多了
最新版Android 11推送!谷歌Pixel 5被曝光:支持反向充电
高度致敬Windows!开源优麒麟20.04 LTS发布:支持5年
电脑小知识:Windows 10是用什么语言写的?到底有多少行代码?
Win10 5月更新准正式版:微软引入大量新功能 系统响应速度快
Windows 10新预览版19613推送:修复任务栏图标显示异常BUG
Windows AD 报错解决:UAC File Virtualization服务启动失败 此驱动程序被阻止加载
网友评论