Concat两个字符串,打印和迭代

时间:2015-05-20 12:33:36

标签: batch-file

如何连接两个字符串来创建目录路径,打印它并获取所有文件?

这是我的尝试:

set today=%date:~10,4%%date:~4,2%%date:~7,2%%
set dir=\\room\c$\temp\here\201505\
set bbb = %dir%%today%-    

@echo %bbb%

bbb变量中,我设置了\\room\c$\temp\here\201505\20150520-但是当我打印它时,我得到-1作为输出。

另一个问题:如何迭代所有以20150520-字符串开头的目录?

1 个答案:

答案 0 :(得分:2)

set "today=%date:~10,4%%date:~4,2%%date:~7,2%"
rem why there was double percent at the end  ^
set "dir=\\room\c$\temp\here\201505\"
set "bbb=%dir%%today%-"
rem     ^- remove spaces around equal sign

@echo %bbb%

迭代文件夹:

for /d  %%a in (20150520-*) do @echo %%~fa