简体   繁体   English

Powershell 脚本获取 csv 文件,其中包含文件夹的文件名和文件大小

[英]Powershell script to get csv file with file name and file size for a folder

I have folder and there are sub folders in it.我有文件夹,里面有子文件夹。 I need file name and size in the csv for all the files in the folder.对于文件夹中的所有文件,我需要 csv 中的文件名大小

This code should work for you这段代码应该适合你

$Directory = "C:\path to directory"
Get-ChildItem -Path $Directory -Recurse -Force | ForEach {
    [PSCustomObject]@{
        Name = $_.Name
        Size = "$([int]($_.length / 1mb)) MB"
    }
} | Export-Csv -Path "./temp.csv" -NoTypeInformation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个 PowerShell 脚本来查找包含数百万个文件的文件夹的文件大小和文件数? - A PowerShell script to find the file size and file count of a folder with millions of files? 使用 Powershell 获取 zip 文件中的文件夹名称 - Get folder name in zip file with Powershell PowerShell查找文件夹/文件大小 - PowerShell to find folder / file size 使用 Powershell 脚本将文件复制到 CSV 文件中声明的特定文件夹 - Copying files to specific folder declared in a CSV file using Powershell Script 如何在csv文件中获取文件名,但在Powershell中截断部分名称? - How to get file names in a csv file but truncate part of the name in powershell? Powershell Script 移动同名不同文件类型到共享文件夹 - Powershell Script to move different file types with the same name to share folder 使用powershell输出多个.csv文件附加.csv文件名作为源文件夹名称 - Output multiple .csv files appending the .csv file name as the source folder name with powershell Powershell获取文件的父文件夹 - Powershell Get Parent Folder of a File 使用 CSV 文件获取用户 HomeDirectory 的文件夹大小 - Get folder size of user HomeDirectory using CSV file 在 Azure 中,使用 powershell 脚本在 csv 文件中获取负载均衡器详细信息 - In Azure, To get Load balancer details in to csv file using powershell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM