Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 337 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run command in each subfolder

#1
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.
Reply

#2
[`svn cleanup`](

[To see links please register here]

) automatically recurses into subdirectories. I'm not sure why you would need to recurse manually for that particular command.
Reply

#3
`for` command is what you are looking for. In order to read about the exact syntax type `for /?`

For example, in order to print the names of all sub directories in the current directory. You can use the command:

for /d /r %i in (*.*) do @echo %i

The echo %i part is the part you must change to suit your case.
Reply

#4
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.

But [Can's answer][1] 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.

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

On the following tree:

<pre>
a
├───.svn
├───a1
│ └───.svn
└───a2
└───.svn
b
├───.svn
├───b1
│ ├───.svn
│ ├───b11
│ │ └───.svn
│ └───b12
│ └───.svn
└───b2
</pre>

This yields the following output:

<pre>
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 "."
</pre>

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.


[1]:

[To see links please register here]

Reply

#5
<!-- language_all: lang-cmd -->

As already stated in [another answer][relans], the [`for /R` command][cmdfrd] helps:

for /D /R %I in ("*") do @echo "%~I"

To explicitly specify the root directory do this:

for /D /R "D:\Root" %I in ("*") do @echo "%~I"

----

Quite the same can be achieved by the [`dir` command][cmddir] together with [`for /F`][cmdfrf]:

for /F "delims=" %I in ('dir /S /B /A:D "D:\Root\*"') do @echo "%~I"

This command line, as well as the aforementioned ones, walk through the directory tree from top to bottom. To reverse that just incorporate the [`sort` command][cmdsrt]:

for /F "delims=" %I in ('dir /S /B /A:D "D:\Root\*" ^| sort /R') do @echo "%~I"

----

All of the above excluds the root directory from being returned. To include it use the following code:

for /F "delims=" %J in ('^(for /R "D:\Root" %I in ^(.^) do @echo "%~fI"^)') do @echo "%~J"

To reverse the order from bottom to top again, use this one:

for /F "delims=" %J in ('^(for /R "D:\Root" %I in ^(.^) do @echo "%~fI"^^^& rem/^) ^| sort /R') do @echo "%~J"


[relans]:

[To see links please register here]

(run command in each subfolder)
[cmdfrd]:

[To see links please register here]

(FOR /R)
[cmdfrf]:

[To see links please register here]

(FOR /F)
[cmddir]:

[To see links please register here]

(DIR)
[cmdsrt]:

[To see links please register here]

(SORT)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through