开发者

Windows batch file: get folders' path and store them in variable

Hello I need a batch file to store in a variable all paths of all directories/subdirectories named ".svn" that I can found in my_folder.

Something like:

@ECHO OFF
FOR /r my_folder %%X IN (.svn) DO (ECHO %%X)

the command above prints them to screen, but I need to store them in a variable as a list of strings. Someone knows how to do it?

This is the site I use for helping myself with batch files: http://ss64.com/nt/

After I want to pass the value of such variable to the command RD in order to delet开发者_开发知识库e them along with this subfolders/files. So let's say the variable is names $a i will do something like:

RD /s /q $a


The simplest solution without any variables is to issue the RD command inside your FOR loop. You can use multiple commands inside the braces like:

@ECHO OFF
FOR /r my_folder %%X IN (.svn) DO (
    ECHO %%X
    RD /s /q %%X
)

If yo need the to add the pathes to a variable you can do it like that:

@ECHO OFF

SET PATH_LIST=
SETLOCAL ENABLEDELAYEDEXPANSION   

FOR /r my_folder %%X IN (.svn) DO (
    ECHO %%X
    SET PATH_LIST=!PATH_LIST! "%%X"
)

ENDLOCAL

RD /s /q %PATH_LIST%

But keep in mind that environment variables are limited in size. In Windows XP a single variable can hold a max. of 8,192 bytes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜