批量获取括号之间的字符串 [英] Get string between parentheses in batch

查看:146
本文介绍了批量获取括号之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是决定学一点点.

因此,为了做些有用的事情,我决定创建一个脚本来整理音乐.它们都是这种格式:

So to do something useful I decided to create a script to organize my musics. They are all in this format:

乐队(专辑)-TrackNumber-TrackName

Band (Album) - TrackNumber - TrackName

我想让我的脚本创建一个带有乐队名称的文件夹,并在其中创建Albuns名称的文件夹.因此,我需要使用文件名,但是我不知道如何使用FINDSTR或任何其他方法来获取´(´之前和括号之间的字符串.我该怎么做?

I want my script to create a folder with the band name and inside it the folder the albuns names. So I need to play with the filename but I don't know how to use the FINDSTR or any other method to get the string before the ´(´ and between the parentesis. How can I do that?

推荐答案

以下是一些很棒的资源,可以助您一臂之力:

Here are some great resources to get you going:

Technet \ DosTips \ SS64 \ Rob van de Woude \ ComputerHope

Technet \ DosTips \ SS64 \ Rob van de Woude \ ComputerHope

这里是如何解析列出的字符串的示例.请注意,如果乐队,专辑或曲目名称中有空格,则此示例将不起作用.

Here is an example of how to parse the string you listed. Note that this example WILL NOT WORK if there are spaces within the band, album, or trackname.

for /f "delims=()- " %%A in ("Band (Album) - TrackNumber - TrackName") do (
    echo Band = "%%~A"
    echo Album = "%%~B"
    echo TrackNumber = "%%~C"
    echo TrackName = "%%~D"
)

输出:

Band = "Band"
Album = "Album"
TrackNumber = "TrackNumber"
TrackName = "TrackName"

但是,此示例通过不使用空格作为定界符来处理空格.不幸的是,这意味着不会从结果中修剪空格.

However, this example will work with spaces by not using them as a delimiter. Unfortunately this means that the spaces will not be trimmed from the results.

for /f "delims=()-" %%A in ("Band Name (Album) - Track Number - Track Name") do (
    echo Band = "%%~A"
    echo Album = "%%~B"
    echo TrackNumber = "%%~C"
    echo TrackName = "%%~D"
)

输出:

Band = "Band Name "
Album = "Album"
TrackNumber = " Track Number "
TrackName = " Track Name"

可以从字符串中修剪空格,但是我将让您学习该技巧:) 提示,请参见上面的链接.

The spaces can be trimmed from the strings, but I will let you learn that technique :) Hint, see the links above.

这篇关于批量获取括号之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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