首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取文本文件大小的批处理脚本

获取文本文件大小的批处理脚本
EN

Stack Overflow用户
提问于 2016-07-21 07:12:00
回答 1查看 107关注 0票数 0

我需要输出作为文本文件读取。这是三个文件。(1)目前我有一个输入文件(2),目前我有一个输出文件(3),实际上我需要输出文件

我有六个.ptp文件。是G码写的。我需要逐行获得与数字(3) 相同的文件大小:大小为"01.ptp“是123290字节

代码语言:javascript
复制
//(1)
@ECHO OFF

set "filename=*.ptp"
set "filename1=*_MachTime.txt"

for %%A in (%filename1%) do ( 
    for %%B in (%filename%) do (
        echo Size of "%%B" is %%~zB bytes >>shop1.txt
        )  
type %%A >>shop1.txt
)

exit​




//(2)

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 

=======================================================================================
LAB12JT01-UG01                                                        Time  26.92 MIN.
O0010         ToolD5_FLAT               S 3000.00  F 300.00                   Z -64.00  mm
--------------------------------------------------------------------------------------

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 

=======================================================================================
LAB12JT01-UG02                                                        Time  2.59 MIN.
O0020         ToolD2X10_FLAT            S 7500.00  F 200.00                   Z -57.20  mm
--------------------------------------------------------------------------------------

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 

=======================================================================================
LAB12JT01-UG03                                                        Time  8.30 MIN.
O0030         ToolD1X4_FLAT             S 7500.00  F 100.00                   Z -56.00  mm
--------------------------------------------------------------------------------------

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 

=======================================================================================
LAB12JT01-UG04                                                        Time  8.03 MIN.
O0040         ToolD1X4_FLAT             S 7500.00  F 100.00                   Z -56.00  mm
--------------------------------------------------------------------------------------

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 

=======================================================================================
LAB12JT01-UG05                                                        Time  7.10 MIN.
O0050         ToolD1_BALL               S 7500.00  F 200.00                   Z -50.27  mm
--------------------------------------------------------------------------------------

Size of "01.ptp" is 123290 bytes 
Size of "02.ptp" is 7714 bytes 
Size of "03.ptp" is 43473 bytes 
Size of "04.ptp" is 41137 bytes 
Size of "05.ptp" is 45802 bytes 
Size of "06.ptp" is 75346 bytes 
​



//////(3)
Size of "01.ptp" is 123290 bytes 
=======================================================================================
LAB12JT01-UG01                                                        Time  26.92 MIN.
O0010         ToolD5_FLAT               S 3000.00  F 300.00                   Z -64.00  mm
--------------------------------------------------------------------------------------

Size of "02.ptp" is 7714 bytes 
=======================================================================================
LAB12JT01-UG02                                                        Time  2.59 MIN.
O0020         ToolD2X10_FLAT            S 7500.00  F 200.00                   Z -57.20  mm
--------------------------------------------------------------------------------------


Size of "03.ptp" is 43473 bytes 
===================================================================================
LAB12JT01-UG03                                                        Time  8.30 MIN.
O0030         ToolD1X4_FLAT             S 7500.00  F 100.00                   Z -56.00  mm
--------------------------------------------------------------------------------------


Size of "04.ptp" is 41137 bytes 
=======================================================================================
LAB12JT01-UG04                                                        Time  8.03 MIN.
O0040         ToolD1X4_FLAT             S 7500.00  F 100.00                   Z -56.00  mm
--------------------------------------------------------------------------------------


Size of "05.ptp" is 45802 bytes
=======================================================================================
LAB12JT01-UG05                                                        Time  7.10 MIN.
O0050         ToolD1_BALL               S 7500.00  F 200.00                   Z -50.27  mm
--------------------------------------------------------------------------------------


Size of "06.ptp" is 75346 bytes 
=======================================================================================
LAB12JT01-UG06                                                        Time  8.69 MIN.
O0060         ToolD0.6_FLAT             S 7500.00  F 100.00                   Z -51.60  mm
--------------------------------------------------------------------------------------
​
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-21 22:00:49

只需定义全局计数器(COUNTER)和本地计数器(COUNTER2)即可。只有当两个计数器匹配时才打印大小。

代码语言:javascript
复制
@ECHO OFF

set "filename=*.ptp"
set "filename1=*_MachTime.txt"
SETLOCAL ENABLEDELAYEDEXPANSION
set COUNTER=0

for %%A in (%filename1%) do (
    set COUNTER2=0

    for %%B in (%filename%) do (
        rem if !COUNTER2!==!COUNTER! echo Size of "%%B" is %%~zB bytes >> shop1.txt
        rem update with size in KB
        set /A KBS=%%~zB/1024
        if !COUNTER2!==!COUNTER! echo Size of "%%B" is !KBS! bytes >> shop1.txt
        set /A COUNTER2=!COUNTER2!+1
        )
    set /A COUNTER=!COUNTER!+1
type %%A >> shop1.txt
)

不太优雅,但嘿,这毕竟是批处理文件,你期待什么?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38497358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档