Windows 批处理文件迭代器问题

发布于 2024-10-18 16:53:15 字数 809 浏览 0 评论 0原文

我有 3 个使用 svn 的项目。我的文件夹系统是:有一个文件夹projects,在projects文件夹中有3个项目projectAprojectBprojectC.

我有一个像这样的 Windows 批处理脚本代码:

d:
cd projectA
svn update
cd ../projectB
svn update
cd ../projectC
svn update

它的目的是使用一个 .bat 文件我想更新我的所有项目。该代码似乎可以改进。是否可以将其更改为:

set folder=projects
set directories=(projectA projectB projectC)
set command=svn update
d:
for %%i in %directories% do cd.. && cd %folder%/%%i && %command%

该代码在某处失败。应该将其更改为 do while 循环或类似的东西,因为它尝试在项目文件夹下创建 cd items\projectB (它应该在项目的上层文件夹中执行 cd items\etc。 )

编辑: @Andriy M 有我电脑的屏幕截图。红色是项目A,蓝色是项目B,紫色是项目C。

在这里: 屏幕截图

I have 3 projects that I use svn for them. My folder system is that: There is a folder projects, within projects folder there are 3 projects projectA, projectB and projectC.

I have a Windows batch script code like that:

d:
cd projectA
svn update
cd ../projectB
svn update
cd ../projectC
svn update

The purpose of it with one .bat file I want to update all of my projects. That code seems like can be improved. Is it possible to change it like:

set folder=projects
set directories=(projectA projectB projectC)
set command=svn update
d:
for %%i in %directories% do cd.. && cd %folder%/%%i && %command%

That code fails on somewhere. It should be change to do while loop or something like that because it tries to make cd projects\projectB while it is under projects folder (It should be at upper folder of projects to execute cd projects\etc.)

EDIT: @Andriy M There is a screenshot from my computer. Red is projectA, blue is projectB and purple is projectC.

Here it:
screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩虹直至黑白 2024-10-25 16:53:15

是什么阻止你像这样实现它:

SET folder=D:\fullpath\project
SET directories=(projectA projectB projectC)
SET command=svn update
FOR %%i IN %directories% DO (CD /D %folder%\%%i && %command%)

What prevents you from implementing it like this:

SET folder=D:\fullpath\project
SET directories=(projectA projectB projectC)
SET command=svn update
FOR %%i IN %directories% DO (CD /D %folder%\%%i && %command%)

?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文