在批处理文件中的字符串中提取数 [英] Extract number from string in batch file

查看:893
本文介绍了在批处理文件中的字符串中提取数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个批处理文件,我想提取数 653456 从以下字符串:

From a batch file I want to extract the number 653456 from the following string:

C:\Users\testing\AppData\Local\Test\abc123\643456\VSALBT81_COM

的数量会发生变化,但它永远只是个数字。

The number will change, however it will always be just digits.

我目前的理论是要搜索的东西,适合 \\ alldigits \\ ,然后更换两个 \\ s的白色的空间,但我不能完全明白这一点。

My current theory is to search for something that fits \alldigits\, then replace the two \s with white space, but I can’t quite get it.

推荐答案

假设数总是父文件夹(在年底前的文件夹):

Assuming the number is always the parent folder (the folder before the end):

@echo off
set "str=C:\Users\testing\AppData\Local\Test\abc123\643456\VSALBT81_COM"
for %%F in ("%str%\..") do set "number=%%~nxF"

这篇关于在批处理文件中的字符串中提取数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆