开发者

How to split delimited text in windows batch?

开发者 https://www.devze.com 2023-02-07 11:37 出处:网络
I have a batch file with an external configuration file. Say I needed to delete files specified in a configuration file as a delimited list on one line. The files could look like this:

I have a batch file with an external configuration file. Say I needed to delete files specified in a configuration file as a delimited list on one line. The files could look like this:

[config.cfg]
*.pdb;*.config

[batch.bat]
...
for /f "tokens=* delims=;" %%b in (%DATA_10%) do (
CALL DEL "%%b%"
)
...

The batch code should iterate through the list of files and delete them.

If I have another external file assigned to %DATA_10% variable which contains the list of files to delete on开发者_如何转开发e per line then it works perfect. However what I need is the files to be extracted from config.cfg as you see above (all on one line) otherwise I would have too many config files required in my batch.

Any idea for a solution?


If config.cfg only contains one line with your data, you could use

set /p DATA_10= < config.cfg

But your FOR /F loop expands only once per line, so it can't work this way. You could change it to

FOR %%a in (%DATA_10%) do (call del "%%b")

But you should be sure not to use * or ?, because they are interpreted as wildcards in a "normal" for-loop

0

精彩评论

暂无评论...
验证码 换一张
取 消