當清單檔案包含不同路徑時,將文字檔案中列出的多個檔案複製到新資料夾

當清單檔案包含不同路徑時,將文字檔案中列出的多個檔案複製到新資料夾

我想將多個文件(具有不同路徑)複製到一個資料夾中。我嘗試了這裡解釋的解決方案stackexchange 上的範例頁面 但是當我運行該文件(我選擇了 .bat 文件)時,我有“0 個文件複製”,如下所示: 螢幕截圖 0 個檔案已複製

這是我的 list.txt 的一些範例:

T:/audio/enregistrements/2023-03-mars/maroc_2023/msd1/test.txt
T:/audio/enregistrements/2023-03-mars/maroc_2023/msd6/20230324_0454_0627_ailes oiseau et cris oiseau indetermine cala iris sentier maroc_35.1287,-4.3661_MKH8020_AB_230324_014.WAV
T:/audio/enregistrements/2023-03-mars/maroc_2023/msd6/20230324_0627_0801_ailes mesange guepier europe et chien ou loup cala iris sentier maroc_35.1287,-4.3661_MKH8020_AB_230324_015.WAV
T:/audio/enregistrements/2023-03-mars/maroc_2023/msd2/20230323_0551_0724_bruant fou fauvette melanocephale ailes pigeon ramier cala iris Maroc_35.1290,-4.3661_MKH8040_ORTF__Z_F3_230323_009.WAV
T:/audio/enregistrements/2023-03-mars/maroc_2023/msd1/20230401_0745_0918_alouette lulu_ifrane Maroc_33.5174,-5.1753_MKH8020_AB230401_014_best best mais avec vent.WAV
T:/audio/enregistrements/2023-03-mars/maroc_2023/nagra/20230401_0954_alouette lulu ifrane maroc_33.5152,-5.1763_telinga dpa 4060 nagra7_Pichard20230401094912_002_best_best.wav

我的 script.bat 位於 T:\audio\enregistrements\2023-03-mars\maroc_2023\ 資料夾中。它包含:

@echo off
for /f "tokens=* delims=" %%a in ('type "T:\audio\enregistrements\2023-03-mars\maroc_2023\list.txt"') do xcopy /hrkvy "%%a" "T:\audio\creation_sonore\projet maroc\complement"
pause

我確定資料夾 T:\audio\creation_sonore\projet maroc\complement 存在。

請問可能是什麼問題?謝謝

答案1

事實上我問了chatgpt,它解決了我的問題。我在這裡發布了使用 powershell 的解決方案:

以下是用於將檔案清單複製到目錄的 PowerShell 腳本:

Get-Content "path\to\file\list.txt" | ForEach-Object {Copy-Item $_ -Destination "path\to\destination\directory"}

確保將“path\to\file\list.txt”替換為包含要複製的檔案清單的文字檔案的完整路徑,並將“path\to\destination\directory”替換為目標目錄的完整路徑(其中)您想複製文件。

它運作得很好:)

相關內容