Skip to content

Instantly share code, notes, and snippets.

@YuukiNishikido
Last active April 12, 2024 10:12
Show Gist options
  • Save YuukiNishikido/2b4008af5c72aabb7acce43ccfa0a81b to your computer and use it in GitHub Desktop.
Save YuukiNishikido/2b4008af5c72aabb7acce43ccfa0a81b to your computer and use it in GitHub Desktop.
PowerShell_特定のフォルダ配下のファイル一覧を大きいサイズ順にCSV出力する
###特定のフォルダ配下の全ファイルのファイルパスと容量をCSV出力する
$files = Get-ChildItem -Path "C:\example" -File -Recurse |
###ファイルサイズをそれぞれKB単位とMB単位で計算し、MB単位の項目で降順にする(ファイルサイズ多い順に出力する)
Select-Object FullName,@{Name="SizeKB"; Expression={[math]::Round($_.Length / 1KB,2)}},@{Name="SizeMB"; Expression={[math]::Round($_.Length / 1MB,2)}} |
Sort-Object -Property SizeMB -Descending
$files | Export-Csv -PAth "C:\result.csv" -Encoding UTF8 -NoTypeInformation
@YuukiNishikido
Copy link
Author

指定したフォルダ配下の全ファイルのファイルパスと容量をCSV出力するPowerShellです。
フォルダの整理に利用できます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment