batch-file - 在 cmd 中获取整数变量的格式化输出

标签 batch-file cmd

我想输出许多名为 file01.txt、file02.txt、...、file10.txt、file11.txt 的文件中的一些数据。我有以下脚本:

setlocal enabledelayedexpansion
set /a cnt = 0
for /f %%f in ('dir /b "../in/"') do (
    set /a cnt += 1
    get_data > ../out/file!cnt!.txt
)

但我得到文件 file1.txt、file2.txt。如何格式化它并添加所需的零?

最佳答案

setlocal enabledelayedexpansion
set /a cnt = 100
for /f %%f in ('dir /b "..\in\"') do (
    set /a cnt += 1
    get_data > ..\out\file!cnt:~-2!.txt
)

批量子串由%var:~m,n%获取,其中,n为可选; m 是从字符串开头开始的字符数,如果为负数,则从末尾开始计数。 ,n 正数 = 返回的最大长度;负数 = 从末尾开始的字符中的结束位置;缺失=返回m

之后的所有内容

关于batch-file - 在 cmd 中获取整数变量的格式化输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21530183/

相关文章:

file - 根据星期几运行批处理文件的一部分

batch-file - 在命令提示符中使用 aws-adfs 时如何指定用户名/密码

windows - 在批处理中的 endlocal 之后保留变量

windows - 如何使 Windows 批处理脚本完全无声?

windows - 调用 "start myapp"和 "myapp"的区别

batch-file - 我如何调用 concat : %variable% when the variable has internal spaces?

powershell - 将输入变量从批处理文件发送到 powershell 脚本

cmd - 如何强制特定应用程序的传出 IP? ForceBindIp 似乎不起作用

windows - 检查所有驱动器(字母和自由大小)并比较高数字自由大小

windows - 运行批处理文件时 cmd 中的奇怪输出