简体   繁体   中英

Copy windows file size from folders only

I would like to write the file size of each file in a particular folder to Excel. How can I do this?

You can use the FileSystemObject object to work with files, folders and textstreams:

''Reference: Windows Script Host Object Model

Dim fs As New FileSystemObject
Dim fldr As Folder
Dim f As File
Dim i As Integer

Set fldr = fs.GetFolder("C:\docs\")

With ActiveWorkbook.Sheets("Sheet3")
    i = 1
    For Each f In fldr.Files
        .Cells(i, 1) = f.Name
        .Cells(i, 2) = f.Size
        i = i + 1
    Next
End With

正如您没有提到任何有关编程的内容一样,我认为这属于SuperUser ,但您只需要选择所有文件,右键单击,选择“属性”,然后复制“大小”即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM