使用增量编号创建一个txt文件

时间:2013-03-04 22:10:11

标签: variables batch-file intervals incremental-build

对不起这个问题我是编程的初学者,对于知道该怎么做的人来说这可能很容易:

我需要在txt文件中创建一系列具有增量数字的链接,例如我想保持某个部分“固定”并且部分必须改变;例如想象一下:

http://user:password@website.com/members/sets/001/somethingfixed-001.zip 在文中,以下行应为:

http://user:password@website.com/members/sets/002/somethingfixed-002.zip 等。

我认为必须有一种方法来生成我可以指定的那些,创建链接保持固定部分在每一行中相等然后逐渐地将001,002,003递增到我需要的点。

如果我能创建一个可以问我的.bat文件,它可能很棒:初始链接是什么,要修复的部分是什么以及要更改的内容。

我会做这样的程序:

插入第一个链接,然后粘贴它。

然后它问我固定部分是什么,我把: ... /构件/套/ X / somethingfixed-Y.zip

变量X和Y的范围是多少? 起始号码?然后我把001然后它问我结束号码是什么?我把150 它会在txt文件中生成链接,以便我可以使用它们。

希望很清楚。

干杯

2 个答案:

答案 0 :(得分:1)

实施例

这将为第一个号码X执行此操作,我将留下一些供您开发和学习。的 :)

@echo off
setlocal EnableExtensions EnableDelayedExpansion
echo LeftXRight Gen
set /p "Left=Left = "
set /p "Right=Right = "
set /p "Start=Begin = "
set /p "End=End = "
>output.txt ( <nul set /p "=" )
for /L %%A in (%Start%, 1, %End%) do (
    set "X=00%%A"
    echo !Left!!X:~-3!!Right!>>output.txt
)
endlocal

输出

LeftXRight Gen
Left = http://user:password@website.com/members/sets/
Right = /somethingfixed.zip
Start = 1
End = 10

output.txt的

http://user:password@website.com/members/sets/001/somethingfixed.zip
http://user:password@website.com/members/sets/002/somethingfixed.zip
http://user:password@website.com/members/sets/003/somethingfixed.zip
http://user:password@website.com/members/sets/004/somethingfixed.zip
http://user:password@website.com/members/sets/005/somethingfixed.zip
http://user:password@website.com/members/sets/006/somethingfixed.zip
http://user:password@website.com/members/sets/007/somethingfixed.zip
http://user:password@website.com/members/sets/008/somethingfixed.zip
http://user:password@website.com/members/sets/009/somethingfixed.zip
http://user:password@website.com/members/sets/010/somethingfixed.zip

更新

为问题添加了这个完整的解决方案。

@echo off
setlocal EnableExtensions EnableDelayedExpansion
echo LeftXMidXRight Gen
set /p "Left=Left = "
set /p "Middle=Middle = "
set /p "Right=Right = "
set /p "Start=Begin = "
set /p "End=End = "
>output.txt ( <nul set /p "=" )
for /L %%A in (%Start%, 1, %End%) do (
    set "X=00%%A"
    echo !Left!!X:~-3!!Middle!!X:~-3!!Right!>>output.txt
)
endlocal

实施例

LeftXMidXRight Gen
Left = http://user:password@website.com/members/sets/
Middle = /somethingfixed-
Right = .zip
Begin = 1
End = 150

output.txt的

http://user:password@website.com/members/sets/001/somethingfixed-001.zip
http://user:password@website.com/members/sets/002/somethingfixed-002.zip
...
http://user:password@website.com/members/sets/150/somethingfixed-150.zip

答案 1 :(得分:0)

这接近你所追求的,有一些限制..

它只能附加到网址的末尾。

1位和2位数字不是前缀零。

@echo off

set /p url="Enter URL: "
set /p start="Start Number: "
set /p end="End Number: "

for /L %%X in (%start%, 1, %end% ) do echo %url% %%X >> file.txt