Windows批处理文件:获取文件夹'路径并将它们存储在变量 [英] Windows batch file: get folders' path and store them in variable
问题描述
您好,我需要一个批处理文件中的一个变量来存储所有目录的所有路径/名为.svn这样我可以在my_folder找到。子目录
是这样的:
@ECHO OFF
FOR / R %% my_folder中的X(.svn文件)DO(ECHO %% X)
上面的命令它们打印到屏幕,但我需要将它们存储在一个变量为字符串列表。有人知道该怎么办呢?
这是我用来帮助自己用批处理文件的网站: http://ss64.com/nt/一>
在我想这些变量的值传递给此命令 RD
,以便与此子文件夹/文件一起删除。
所以我们说的变量名称 $ A
我会做这样的事情:
RD / S / Q $一个
没有任何变量最简单的办法是发行中的 RD
命令你的 FOR
循环。您可以使用大括号内的多个命令,如:
@ECHO OFF
FOR / R %% my_folder中的X(.svn文件)DO(
ECHO %%点¯x
RD / S / Q %%点¯x
)
如果哟需要到pathes添加到一个变量,你可以做这样的:
@ECHO OFFSET路径列表=
SETLOCAL ENABLEDELAYEDEXPANSIONFOR / R %% my_folder中的X(.svn文件)DO(
ECHO %%点¯x
SET路径列表=!路径列表! %%X
)ENDLOCALRD / S / Q%路径列表%
但请记住,环境变量的大小限制。在Windows XP中单个变量可以容纳最大。 8192字节。
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.
这篇关于Windows批处理文件:获取文件夹'路径并将它们存储在变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!