处理文件名中的空间,FOR循环,批处理
问题描述:
我试图在使用文件的内容作为输入之前,找到给定目录中的所有MP3文件,然后将其导出到文件。处理文件名中的空间,FOR循环,批处理
文件复制的所有实例工作正常,除了包含空格的文件位置。我应该如何在当前的代码中解决这个问题。请参考下面的截图我MP3_Location.txt文件
内容是:
C:\Test\asdad.MP3
C:\Test\New folder\werwer.MP3
C:\Test\OneDrive - Backup\asdasdasdad.MP3
REM Exporting the location of the MP3 file in a given directory
DIR /s/b "C:\Test\*.MP3" >> C:\Software\MP3_Location.txt
REM Trying to copy the files based on the previous Output
FOR /F %%G IN (C:\Software\MP3_Location.txt) DO c:\windows\system32\xcopy
"%%G" C:\Software\MP3\ /Y
编辑1:正在尝试使用Delims,所建议的(也许不使用它正确)
REM Exporting the location of the MP3 file in a given directory
DIR /s/b "C:\Test\*.MP3" >> C:\Software\MP3_Location.txt
REM Trying to copy the files
FOR /F %%G "tokens=* delims=" IN (C:\Software\MP3_Location.txt) DO c:\windows\system32\xcopy "%%G" C:\Software\MP3\ /Y
答
使用命令
FOR /F "delims=" %%G IN
您需要使用delims选项来告诉FOR命令不使用任何分隔符。 – Squashman
@squashman尝试循环中的分隔符,但它仍然不起作用。 – user3839914
你知道你不必首先创建文件列表。你可以使用'FOR/R'命令遍历文件'FOR/RC:\ TEST %% G IN(* .mp3)do'或者使用'FOR/F'命令并使用'DIR'命令:'FOR/F“delims =”%% G IN('dir/b/s * .mp3')do ....'。 – Squashman