batch-file - 处理文件名中的空格、FOR 循环、批处理

标签 batch-file for-loop input whitespace

我试图查找给定目录中的所有 MP3 文件,然后将其导出到文件,然后尝试使用文件的内容作为输入。

文件复制的所有实例都工作正常,但包含空格的文件位置除外。我应该如何在当前的代码中解决这个问题。请引用下面的截图

我的 MP3_Location.txt 文件的内容是:

C:\Test\asdad.MP3
C:\Test\New folder\werwer.MP3
C:\Test\OneDrive - Backup\asdasdasdad.MP3

File location with spaces not working

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

关于batch-file - 处理文件名中的空格、FOR 循环、批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46781106/

相关文章:

javascript - 通过单击元素并将该属性传递给字段,让输入字段识别它已被填充

java - 就阴影而言,Java 中的 for each 和传统 for 循环有什么区别?

c++ - 将批处理文件转换为exe

batch-file - 从命令行停止然后启动 EC2

windows - 如何使用 powershell 将反斜杠 CR LF 替换为 <br>

python for循环,如何找到下一个值(对象)?

c - 二维数组打印不正确

Linux Shell 脚本输入

javascript - 如果使用 javascript 创建输入类型文本,则无法在 ie 11 中输入! :(

windows - 如何在DOS/win命令提示符/Windows批处理文件中停止Windows服务后删除dll