用於將檔案從所有可用磁碟機複製到 USB 的批次腳本

用於將檔案從所有可用磁碟機複製到 USB 的批次腳本

我有這個腳本

    for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do (
    copy "%%x\*.spt" "%drive%\mydiagtools"
)
pause

我需要它將具有 SPT 擴展名的文件(我們專有的公司文件)從特定計算機上的所有可用磁碟複製到我的 USB 驅動器。

有人知道為什麼它不起作用嗎?這是我得到的輸出:

F:\>for /F "skip=1 delims=" %x in
*.spt" "\mydiagtools" )

\*.spt" "\mydiagtools" )
The device is not ready.

\*.spt" "\mydiagtools" )
\*.spt
The filename, directory name, or v
        0 file(s) copied.

\*.spt" "\mydiagtools" )
The device is not ready.

\*.spt" "\mydiagtools" )
The device is not ready.

\*.spt" "\mydiagtools" )
\*.spt
The filename, directory name, or v
        0 file(s) copied.

\*.spt" "\mydiagtools" )
\*.spt
The system cannot find the path sp
        0 file(s) copied.

\*.spt" "\mydiagtools" )
\*.spt
The filename, directory name, or v
        0 file(s) copied.

F:\>pause
Press any key to continue . . .

非常感謝

編輯:更正輸出

答案1

你想使用powershell嗎?請嘗試以下腳本。

$copy=Get-PSDrive -PSProvider FileSystem  |  %{ Get-ChildItem $_.Root -Recurse -force  -ErrorAction SilentlyContinue| Where-Object {$_.Extension -eq '.spt'}} Copy-Item -Path $copy.Fullname -Destination  C:\xxxx\

在腳本的最後,請修改為您的USB,然後以powershell執行。

答案2

以下程式碼應該可以工作:

for /f "skip=1" %%x in ('wmic logicaldisk get caption') do (
    copy "%%x\*.spt" "%drive%\mydiagtools"
)
pause

儘管%drive%對我來說沒有任何價值,但問題似乎與delims=.沒有它,我可以成功列出和複製驅動器的內容,但卻delims=會導致不顯示或複製任何文件的不良副作用。

(在 Windows 10 Enterprise x64 版本 1803 build 10.0 下測試。17134.376

相關內容