2017-10-17 244 views
1

我試圖在使用文件的內容作爲輸入之前,找到給定目錄中的所有MP3文件,然後將其導出到文件。處理文件名中的空間,FOR循環,批處理

文件複製的所有實例工作正常,除了包含空格的文件位置。我應該如何在當前的代碼中解決這個問題。請參考下面的截圖我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 
+1

您需要使用delims選項來告訴FOR命令不使用任何分隔符。 – Squashman

+0

@squashman嘗試循環中的分隔符,但它仍然不起作用。 – user3839914

+1

你知道你不必首先創建文件列表。你可以使用'FOR/R'命令遍歷文件'FOR/RC:\ TEST %% G IN(* .mp3)do'或者使用'FOR/F'命令並使用'DIR'命令:'FOR/F「delims =」%% G IN('dir/b/s * .mp3')do ....'。 – Squashman

回答