我正在尝试读取文件名和路径,并将其存储在单个变量中,用逗号区分每个路径。下面是我的尝试,但每次如果我运行它显示单个文件名,即使它在for循环中运行。
代码:
Everyone
文件夹包含文件: C:\ Users \用户a5100893 \桌面\ SOURCE_FILES \
@echo off
for %%F in ("C:\Users\a5100893\Desktop\source_files\*.*") do (
set file=%%F
echo done copying files: %file%
)
输出:
Pwm_1.txt
Pwm_2.txt
Pwm_3.txt
Pwm_4.txt
Pwm_5.txt
预期产出:
变量"文件"应包含:
" C:\用户\ a5100893 \桌面\ SOURCE_FILES \ Pwm_1.txt,C:\用户\ a5100893 \桌面\ SOURCE_FILES \ Pwm_2.txt,C:\用户\ a5100893 \桌面\ SOURCE_FILES \ Pwm_3.txt,C :\用户\ a5100893 \桌面\ SOURCE_FILES \ Pwm_4.txt,C:\用户\ a5100893 \桌面\ SOURCE_FILES \ Pwm_5.txt"
答案 0 :(得分:0)
您可以使用以下内容:
@Echo Off
For %%A In ("C:\Users\a5100893\Desktop\source_files\*") Do If Not Defined file (
Set "file=%%A") Else Call Set "file=%%file%%,%%A"
Echo %file%
Timeout -1