批处理文件:从文本文件中读取路径,并存储每个实例作为新的变量? [英] Batch File: Read path from text file and store every instance as new variable?

查看:175
本文介绍了批处理文件:从文本文件中读取路径,并存储每个实例作为新的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取文本文件的内容,并存储在每一行成自己的变量中找到的任何路径。有每行只有1路,并在每一行有其它文本(双引号,数字和标签)。

这甚至可能吗?我花了周围6小时淘Bing和谷歌试图找出如果我能做到这一点,我还没有发现任何东西。

下面是该文本文件的例子:

 LibraryFolders
{
  1D:\\\\ Steam游戏
  2,E:\\\\ Steam游戏
}

上市库文件夹和库文件夹的路径的数量将是每一个用户的计算机上有所不同。


解决方案

@ECHO OFF
SETLOCAL
::除去起始$变量
FOR / Fdelims ==%% a。在('设置$ 2 ^>讷')DO SET一%% =
FOR / F令牌= 1 *%%一个IN(q27630202.txt)DO(
 IF%%〜BNEQSET$ %%〜一= %%〜B

SET $GOTO:EOF

我用命名包含您的数据,我的测试文件 q27630202.txt

I'm trying to read the contents of a text file and store any paths found on each line into their own variable. There's just 1 path on each line and also on each line there's other text (double quotes, a number and a tab).

Is this even possible? I've spent around 6 hours scouring Bing and Google trying to find out if i can do this and i haven't found anything.

Here's an example of the text file:

"LibraryFolders"
{
  "1"       "D:\\Steam Games"
  "2"       "E:\\Steam Games"
}

The number of library folders listed and path of the library folder will be different for every user's computer.

解决方案

@ECHO OFF
SETLOCAL
:: remove variables starting $
FOR  /F "delims==" %%a In ('set $ 2^>Nul') DO SET "%%a="
FOR /f "tokens=1*" %%a IN (q27630202.txt) DO (
 IF "%%~b" neq "" SET "$%%~a=%%~b"
)
SET $

GOTO :EOF

I used a file named q27630202.txt containing your data for my testing.

这篇关于批处理文件:从文本文件中读取路径,并存储每个实例作为新的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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