Windows command for file size only

后端 未结 12 1825
死守一世寂寞
死守一世寂寞 2020-11-27 16:12

Is there a Windows command that will output the size in bytes of a specified file like this?

> filesize test.jpg
65212

I know that the d

相关标签:
12条回答
  • 2020-11-27 16:39

    In PowerShell you should do this:

    (Get-ChildItem C:\TEMP\file1.txt).Length
    
    0 讨论(0)
  • 2020-11-27 16:41

    Try forfiles:

    forfiles /p C:\Temp /m file1.txt /c "cmd /c echo @fsize"
    

    The forfiles command runs command c for each file m in directory p.

    The variable @fsize is replaced with the size of each file.

    If the file C:\Temp\file1.txt is 27 bytes, forfiles runs this command:

    cmd /c echo 27
    

    Which prints 27 to the screen.

    As a side-effect, it clears your screen as if you had run the cls command.

    0 讨论(0)
  • 2020-11-27 16:43

    Taken from here:

    The following command finds folders that are greater than 100 MB in size on the D: drive:

    diruse /s /m /q:100 /d d:
    

    The /s option causes subdirectories to be searched, the /m option displays disk usage in megabytes, the /q:100 option causes folders that are greater than 100 MB to be marked, and the /d option displays only folders that exceed the threshold specified by /q.

    Use the diskuse command to find files over a certain size. The following command displays files over 100 MB in size on the D: drive:

    diskuse D: /x:104857600 /v /s
    

    The /x:104857600 option causes files over 104,857,600 bytes to be displayed and is valid only if you include the /v option (verbose). The /s option means subdirectories from the specified path (in this case, the D: drive) are searched.

    Using VBScript

    ' This code finds all files over a certain size.
    ' ------ SCRIPT CONFIGURATION ------
    strComputer = "**<ServerName>**" 
    intSizeBytes = 1024 * 1024 * 500  ' = 500 MB
    ' ------ END CONFIGURATION ---------
    set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    set colFiles = objWMI.ExecQuery _
        ("Select * from CIM_DataFile where FileSize > '" & intSizeBytes & "'")
    for each objFile in colFiles
        Wscript.Echo objFile.Name & "  " & objFile.Filesize / 1024 / 1024 & "MB"
    next
    
    0 讨论(0)
  • 2020-11-27 16:45

    Since you're using Windows XP, Windows PowerShell is an option.

    (Get-Item filespec ).Length 
    

    or as a function

    function Get-FileLength { (Get-Item $args).Length }
    Get-FileLength filespec
    
    0 讨论(0)
  • 2020-11-27 16:50

    In PowerShell you can do:

    $imageObj = New-Object System.IO.FileInfo("C:\test.jpg")    
    $imageObj.Length
    
    0 讨论(0)
  • 2020-11-27 16:52

    Create a file named filesize.cmd (and put into folder C:\Windows\System32):

    @echo %~z1
    
    0 讨论(0)
提交回复
热议问题