如何使用批处理将文件复制并粘贴到文件夹中

时间:2014-11-19 10:28:57

标签: batch-file xcopy

我想创建一个批处理文件,用于复制文件夹的内容并将其粘贴到另一个文件夹中。说

     source: D:\backup\test
destination: D:\backup1

但是我想在目标中创建一个子文件夹,我可以粘贴文件。

 @echo off
   :: variables

   echo Backing up file
   set /P source=Enter source folder:
   set /P destination=Enter Destination folder:

   set listfile=xcopy /L
   set xcopy=xcopy /S/E/V/Q/F/H

   %listfile% %source% %destination%

   echo files will be copy press enter to proceed
   pause

   %xcopy% %source% %destination%
   pause

3 个答案:

答案 0 :(得分:1)

这对你有帮助......

set FOLDER_CURRENT=%cd%
set VERSION= what u want
set FOLDER_SRC= what u want
set FOLDER_OUT= what u want
mkdir %FOLDER_OUT%

echo * Create the file xcopy_EXCLUDE.txt in order to ignore some file and directory.
echo *   - ignore all .au3 files
echo *   - ignore all .pspimage files
echo *   - ignore the \psp\ directory
echo .au3 > xcopy_Exclude.txt
echo .pspimage >> xcopy_Exclude.txt
echo \psp\ >> xcopy_Exclude.txt
echo * The file xcopy_EXCLUDE.txt is created.
echo.
echo * Copy files with xcopy.
xcopy "%FOLDER_SRC%" "%FOLDER_OUT%" /E /H /Y /EXCLUDE:xcopy_Exclude.txt

echo * Files and directory are copied.
echo.
echo * Delete xcopy_Exclude.txt.

del xcopy_Exclude.txt

答案 1 :(得分:1)

if not exist检查目录是否存在。如果没有,mkdir会创建它。

@echo off

echo Backing up the file
set /p source=Enter source folder: 
set /p destination=Enter destination folder: 

if not exist %destination% mkdir %destination%
set listfile=xcopy /L
set xcopy=xcopy /S/E/V/Q/F/H

%listfile% %source% %target%
echo Files listed will be copied.
pause

%xcopy% %source% %destination%

答案 2 :(得分:1)

this is my script which i got success..

@echo off
:: variables
echo Backing up file
set /P source=Enter source folder:
set /P destination=Enter Destination folder:
set /P Folder=Enter Folder name:
@echo folder=%folder%
mkdir %destination%\%folder%
set xcopy=xcopy /S/E/V/Q/F/H/I
%xcopy% %source% %destination%\%folder%
echo files will be copy press enter to proceed
pause