在每个子文件夹中运行命令 [英] run command in each subfolder

查看:91
本文介绍了在每个子文件夹中运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在路径的每个子文件夹中运行命令的最简单方法是什么?在这种情况下,我必须对存储库中的每个目录运行svn cleanup.

What is the easiest way to run a command in each subfolder of a path? In this case I have to run svn cleanup for every directory in my repository.

推荐答案

我发现在这种情况下,删除工作副本并重新签出要容易得多.如果您有本地更改,请先将更改的文件复制到其他位置.

I have found that in such cases it is much easier to just delete the working copy and re-checkout. If you have local changes, then copy the changed files elsewhere first.

但是可以的答案可能适用于您的情况,除非SVN有更大的问题.尽管您可能必须运行几次,因为它会从仍然存在问题的根文件夹开始.在这种情况下,您需要某种后序遍历,这不能通过for /r完成,但可以确保从层次结构中最低的目录开始进行清理.

But Can's answer might work in your case, unless SVN has greater problems. Though you probably have to run it several times since it would begin at the root folder which would still have problems, then. You'd need some kind of post-order traversal in that case which can't be done with for /r but which can ensure that you would start with the lowest directories in the hierarchy to clean up.

您还需要排除SVN的状态保存目录.svn:

You'd also need to exclude SVN's statekeeping directories .svn:

for /r /d %i in (*) do if NOT %i==.svn svn cleanup %i

关于后遍历,您可以构建一些批处理:

As for the post-order traversal, you can build a little batch:

@echo off
call :recurse "."
goto :eof

:recurse
pushd %1
if not %~1==.svn (
    for /d %%i in (*) do call :recurse "%%i"
    echo svn cleanup %~1
)
popd
goto :eof

在以下树上:


a
├───.svn
├───a1
│   └───.svn
└───a2
    └───.svn
b
├───.svn
├───b1
│   ├───.svn
│   ├───b11
│   │   └───.svn
│   └───b12
│       └───.svn
└───b2

这将产生以下输出:


svn cleanup "a1"
svn cleanup "a2"
svn cleanup "a"
svn cleanup "b11"
svn cleanup "b12"
svn cleanup "b1"
svn cleanup "b2"
svn cleanup "b"
svn cleanup "."

如您所见,

可确保首先处理最低目录,并跳过.svn目录.如果要使用echo,请将其删除.这样可以解决您的问题.也许.

which, as you can see, makes sure that the lowest directories are processed first and the .svn directories are skipped. Remove the echo if you want to use it. This could resolve your problem. Maybe.

这篇关于在每个子文件夹中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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