Bagaimana cara mengekspor struktur hierarki direktori (dengan Detail File yang Diperluas)?

0

Saya perlu daftar hierarkis semua file bersama dengan Detail File yang Diperpanjang .

Pertanyaan saya mirip dengan Bagaimana saya bisa mengekspor struktur direktori? Kedua jawaban yang menyebutkan perintah tree dan Get-ChildItem baik untuk saya, tetapi saya hanya ingin menambahkan setiap item Detail File Diperpanjang .

Rincian File Diperpanjang yang saya inginkan adalah:

  • Path Lengkap (misalnya I:\MS\Ly\Video\122453.mp4)
  • Jenis File (dalam format EXT - DESCRIPTION, mis. MP4 - MPEG-4 video files)
  • Ukuran (mis. 21.78 MB) (Juga, saya harus dapat menampilkan ini dalam byte)
  • Dibuat (Tanggal pembuatan file, mis. 21-Nov-17 1:45:15 AM)
  • Dimodifikasi (Tanggal modifikasi file, mis. 21-Nov-17 1:45:17 AM)
  • Diakses (Tanggal akses file terakhir, mis. 23-Nov-17 2:30:03 PM)

Contoh Detail File Diperpanjang yang bisa saya dapatkan dari menu konteks di Bulk Rename Utility :

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

Contoh output yang saya inginkan:

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»]

Saya berencana untuk mengembangkan solusi semacam itu (jika tidak ada) menggunakan AutoHotkey. Jadi saya akan memposting pertanyaan pemrograman khusus yang terpisah pada StackOverflow terkait dengan pertanyaan ini. Saya akan menaruh tautan ke mereka di sini segera setelah saya mempostingnya (kalau-kalau seseorang dengan pengalaman pemrograman ingin berbagi beberapa jawaban yang akan meningkatkan jawaban dari pertanyaan pengguna-super ini).

Omar
sumber

Jawaban:

0

Get-ChildItemakan bekerja tetapi tidak akan menunjukkan tingkat hierarki seperti treekehendak. Masalah dengan menggunakan treeuntuk ini adalah tidak lewat objek, menambah kesulitan untuk mendapatkan properti setiap item. Kita perlu melakukan pipe treeto ForEach-Object, parsing setiap hasil dari kanan sampai Anda menekan satu daun (tidak menjadi bingung dengan karakter khusus potensial di setiap file atau nama direktori), kemudian permintaan untuk properti.

Anda dapat melakukannya, dan ada banyak pendekatan untuk ini, tetapi Anda mungkin ingin mencari solusi yang ada terlebih dahulu.

Lihat Show-Tree(baris 1633-1866) dari proyek Ekstensi Komunitas PowerShell (PSCX). Output dari Show-Tree -ShowLeaf -ShowPropertysangat dekat dengan kriteria Anda, meskipun properti yang diperluas tidak bergabung dengan objek sumber.

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
akar
sumber