我需要所有文件的层次列表随着 扩展文件详细信息。
我的问题类似于如何导出目录结构?两个答案都提到树和获取子项命令对我来说很好,但我只想向每个项目添加扩展文件详细信息。
我想要的扩展文件详细信息是:
- 完整路径(例如
I:\MS\Ly\Video\122453.mp4
) - 文件类型(格式为 EXT - DESIGN,例如
MP4 - MPEG-4 video files
) - 大小(例如
21.78 MB
)(此外,我需要能够以字节为单位显示) - 创建时间(文件创建日期,例如
21-Nov-17 1:45:15 AM
) - 修改时间(文件修改日期,例如
21-Nov-17 1:45:17 AM
) - 访问时间(上次文件访问日期,例如
23-Nov-17 2:30:03 PM
)
示例扩展文件详细信息我可以从上下文菜单中获取批量重命名实用程序:
Filename Parent Folder Full Path File Type Size Created Modified Accessed
122453.mp4 Video I:\MS\Ly\Video\122453.mp4 MP4 - MPEG-4 video files 21.78 MB 21-Nov-17 1:45:15 AM 21-Nov-17 1:45:17 AM 23-Nov-17 2:30:03 PM
我想要的输出示例:
I:
├───Folder A ■[▪«Parent Folder: I:\», ▪«Full Path: I:\Folder A», ▪«File Type: File folder», «Size: 65.34 MB (65,343,693 B) — Contains: 3 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───File A1.mp4 ■[▪«Parent Folder: Folder A», ▪«Full Path: I:\Folder A\File A1.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───File A2.mp4 ■[▪«Parent Folder: Folder A», ▪«Full Path: I:\Folder A\File A2.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ └───File A3.mp4 ■[▪«Parent Folder: Folder A», ▪«Full Path: I:\Folder A\File A3.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
├───Folder B ■[▪«Parent Folder: I:\», ▪«Full Path: I:\Folder B», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ └───File B1.mp4 ■[▪«Parent Folder: Folder B», ▪«Full Path: I:\Folder B\File B1.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B)», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
├───Folder C ■[▪«Parent Folder: I:\», ▪«Full Path: I:\Folder C», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 1 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ └───Folder C1 ■[▪«Parent Folder: Folder C», ▪«Full Path: I:\Folder C\Folder C1», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ └───File C1a.mp4 ■[▪«Parent Folder: Folder C1», ▪«Full Path: I:\Folder C\Folder C1\File C1a.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
├───Folder D ■[▪«Parent Folder: I:\», ▪«Full Path: I:\Folder D», ▪«File Type: File folder», «Size: 87.12 MB (87,124,924 B) — Contains: 4 Files, 6 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───Folder D1 ■[▪«Parent Folder: Folder D», ▪«Full Path: I:\Folder D\Folder D1», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 2 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ └───Folder D1a ■[▪«Parent Folder: Folder D1», ▪«Full Path: I:\Folder D\Folder D1\Folder D1a», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 1 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ └───Folder D1a1 ■[▪«Parent Folder: Folder D1a», ▪«Full Path: I:\Folder D\Folder D1\Folder D1a\Folder D1a1», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ └───File D1a1a.mp4 ■[▪«Parent Folder: Folder D1a1», ▪«Full Path: I:\Folder D\Folder D1\Folder D1a\Folder D1a1\File D1a1a.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───Folder D2 ■[▪«Parent Folder: Folder D», ▪«Full Path: I:\Folder D\Folder D2», ▪«File Type: File folder», «Size: 21.78 MB (21,781,231 B) — Contains: 1 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ └───File D2a.mp4 ■[▪«Parent Folder: Folder D2», ▪«Full Path: I:\Folder D\Folder D2\File D2a.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───Folder D3 ■[▪«Parent Folder: Folder D», ▪«Full Path: I:\Folder D\Folder D3», ▪«File Type: File folder», «Size: 43.56 MB (43,562,462 B) — Contains: 2 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ ├───File D3a.mp4 ■[▪«Parent Folder: Folder D3», ▪«Full Path: I:\Folder D\Folder D3\File D3a.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ │ └───File D3b.mp4 ■[▪«Parent Folder: Folder D3», ▪«Full Path: I:\Folder D\Folder D3\File D3b.mp4», ▪«File Type: MP4 - MPEG-4 video files», «Size: 21.78 MB (21,781,231 B) », ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
│ ├───Folder D4 ■[▪«Parent Folder: Folder D», ▪«Full Path: I:\Folder D\Folder D4», ▪«File Type: File folder», «Size: 0 — Contains: 0 Files, 0 Folders», ▪«Created: 21-Nov-17 1:45:15 AM», ▪«Modified: 21-Nov-17 1:45:17 AM», ▪«Accessed: 23-Nov-17 2:30:03 PM»]
我计划使用 AutoHotkey 开发这样的解决方案(如果不存在的话)。因此,我将在 StackOverflow 上发布与此问题相关的单独编程特定问题。我会在发布后立即在此处放置链接(以防有编程经验的人想分享一些答案,从而促进这个超级用户问题的回答)。
答案1
Get-ChildItem
可以工作,但不会像tree
will 那样显示层次结构。使用 的一个问题tree
是它不会传递对象,这增加了获取每个项目属性的难度。我们需要通过管道传输tree
到ForEach-Object
,从右侧解析每个结果,直到找到一个叶子(不要与每个文件或目录名称中的潜在特殊字符混淆),然后查询属性。
您可以做到这一点,并且有很多方法可以实现这一点,但您可能想先寻找现有的解决方案。
查看Show-Tree
(1633-1866 行)来自PowerShell 社区扩展Show-Tree -ShowLeaf -ShowProperty
项目(PSCX)。虽然扩展属性未加入源对象,但的输出非常接近您的标准。
C:\users\username\Desktop
├──Property: Attributes = ReadOnly, Directory
├──Property: BaseName = Desktop
├──Property: CreationTime = 12/03/2017 16:43:05
├──Property: CreationTimeUtc = 12/03/2017 21:43:05
├──Property: Exists = True
├──Property: Extension =
├──Property: FullName = C:\users\username\Desktop
├──Property: LastAccessTime = 12/17/2017 10:07:29
├──Property: LastAccessTimeUtc = 12/17/2017 15:07:29
├──Property: LastWriteTime = 12/17/2017 10:07:29
├──Property: LastWriteTimeUtc = 12/17/2017 15:07:29
├──Property: LinkType =
├──Property: Mode = d-r---
├──Property: Parent = username
├──Property: Root = C:\
├──Property: Target =
├──test.ps1
│ ├──Property: Attributes = Archive
│ ├──Property: BaseName = test
│ ├──Property: CreationTime = 12/16/2017 08:24:22
│ ├──Property: CreationTimeUtc = 12/16/2017 13:24:22
│ ├──Property: Directory = C:\users\username\Desktop
│ ├──Property: DirectoryName = C:\users\username\Desktop
│ ├──Property: Exists = True
│ ├──Property: Extension = .ps1
│ ├──Property: FullName = C:\users\username\Desktop\test.ps1
│ ├──Property: IsReadOnly = False
│ ├──Property: LastAccessTime = 12/16/2017 10:46:37
│ ├──Property: LastAccessTimeUtc = 12/16/2017 15:46:37
│ ├──Property: LastWriteTime = 12/16/2017 10:46:37
│ ├──Property: LastWriteTimeUtc = 12/16/2017 15:46:37
│ ├──Property: Length = 3285
│ ├──Property: LinkType =
│ ├──Property: Mode = -a----
│ ├──Property: Target =
│ └──Property: VersionInfo = File: C:\users\username\Desktop\test.ps1
└──Artist - Title (Full Album).mp3
├──Property: Attributes = Archive
├──Property: BaseName = Artist - Title (Full Album)
├──Property: CreationTime = 12/15/2017 20:24:41
├──Property: CreationTimeUtc = 12/16/2017 01:24:41
├──Property: Directory = C:\users\username\Desktop
├──Property: DirectoryName = C:\users\username\Desktop
├──Property: Exists = True
├──Property: Extension = .mp3
├──Property: FullName = C:\users\username\Desktop\Artist - Title (Full Album).mp3
├──Property: IsReadOnly = False
├──Property: LastAccessTime = 12/15/2017 20:24:41
├──Property: LastAccessTimeUtc = 12/16/2017 01:24:41
├──Property: LastWriteTime = 12/15/2017 20:25:34
├──Property: LastWriteTimeUtc = 12/16/2017 01:25:34
├──Property: Length = 45120000
├──Property: LinkType =
├──Property: Mode = -a----
├──Property: Target =
└──Property: VersionInfo = File: C:\users\username\Desktop\Artist - Title (Full Album).mp3