簡體   English   中英

使用Windows命令將非xml文件從一個目錄復制到另一個目錄

[英]Copy non xml files from one directory to another using windows command

我有一個源文件夾,其中有xml文件和非xml文件。 我只需要將非xml文件從源復制到目標文件夾。 我寫了下面的命令,該命令會將xml文件從源文件夾復制到目標文件夾。 但是我需要非xml文件。 請幫助。

@echo on
set SRCROOT=D:\input
set DESTNAME=D:\archive

echo Creating Directories...
if not exist %DESTNAME% md %DESTNAME%

echo Copying Files...
copy /Y %SRCROOT%\*.xml %DESTNAME%

更新:我嘗試如下,它的工作。 遍歷目錄並復制所有非xml文件:

@echo on
set SRCROOT=D:\input
set DESTNAME=D:\archive

echo Creating Directories...
if not exist %DESTNAME% md %DESTNAME%

@echo off
for %%i in (%SRCROOT%\*.*) do if not "%%~xi" == ".xml" copy /Y %%i %DESTNAME%

請改用robocopy 從Windows7開始,它在操作系統中可用。 /xf選項允許您排除文件,例如*.xml

robocopy %SRCROOT% %DESTNAME% * /xf *.xml

否則,xcopy具有/exclude選項,但是需要一個文件。 請參閱xcopy中的/ exclude僅了解文件類型

xcopy具有排除選項:

echo .xml >>c:\temp\exclude.txt
xcopy %SRCROOT%\*.* %DESTNAME% /exclude:c:\temp\exclude.txt
del c:\temp\exclude.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM