사용 가능한 모든 드라이브의 파일을 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

파워셸을 사용하시겠습니까? 다음 스크립트를 시도해 보십시오.

$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 빌드 10.0에서 테스트되었습니다.17134.376)

관련 정보