使用批处理文件循环目录名称?
问题描述:
假设我具有以下结构:
d:/
-- /alpha/
-- /beta/
-- /gamma/
-- /delta/
我正在尝试执行一个通过这些文件夹的批处理文件(但不通过其中的子文件夹).
I'm trying to execute a batch file that goes through those folders (but not through sub-folders within them).
如何使用FOR LOOP获得此结果(假设我不知道文件夹的名称和数量):
How do I get this result using a FOR LOOP (assuming I don't know the name and quantity of the folders):
ren alpha alpha1
ren beta beta1
ren gamma gamma1
ren delta delta1
答
这就是您所需要的:
for /D %i in (*) do rename "%i" "%i1"
/D 根据帮助对目录名称执行命令,可以使用命令for /?
The /D performs the command against the directory names, as per the help, which can be obtained using the command for /?
如果启用了命令扩展,则以下的其他形式 支持FOR命令:
If Command Extensions are enabled, the following additional forms of the FOR command are supported:
FOR/D%IN输入变量(设置)DO命令[命令参数]
FOR /D %variable IN (set) DO command [command-parameters]
If set contains wildcards, then specifies to match against directory
names instead of file names.