【问题标题】:Command for getting the file size获取文件大小的命令
【发布时间】:2012-08-21 10:42:07
【问题描述】:

谁能告诉我一个适用于 Windows 7 的 shell 命令,它将文件路径作为参数并返回该文件的大小 - 类似于:

fileSize.cmd file.txt

...这会给我1KB

SO 中的一个问题注意到命令echo %~z1,但为此,我必须编写一个单独的批处理文件并在其中使用此命令。我正在考虑修改我现有的 bat 文件并以某种方式合并此命令。我的批处理文件如下所示:

p4 diff //sources/j2cs/output.txt >> diff_out.txt

我必须在现有的bat文件中添加上面的命令才能找到diff_out.txt的文件大小。

【问题讨论】:

    标签: batch-file windows-7 filesize


    【解决方案1】:

    另一种变体:

    @echo off
    
    set file=c:\bookmarks.html
    
    %1 %0 :: %file%
    set len=%~z2
    echo %len% 
    
    pause
    

    或使用 wmic:

    D:\>set wql="drive='g:' and filename='function2' and extension='txt'"
    
    D:\>wmic path cim_datafile where %wql% get name,filesize
    FileSize  Name
    621       g:\function2.txt
    
    D:\>
    

    或:

    set file=G:\function2.txt
    
    echo set len=%%~z1 >_tmp.bat
    call _tmp.bat %file% && del _tmp.bat
    echo %len%
    

    【讨论】:

      【解决方案2】:

      您不需要额外的批处理文件,您可以通过调用函数将文件名移动到 %1 中,或者您可以使用 FOR 循环。

      call :getFilesize diff_out.txt
      echo %fileSize%
      exit /b
      
      :getFilesize
      set filesize=%~z1
      exit /b
      

      或者

      for %%A in (diff_out.txt) do set fileSize=%%~zA
      

      【讨论】:

        猜你喜欢
        • 2019-10-29
        • 2012-09-30
        • 1970-01-01
        • 1970-01-01
        • 2012-04-23
        • 2020-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多