当前位置: 动力学知识库 > 问答 > 编程问答 >

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 delete 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: