【问题标题】:how to copy and paste file into folder using batch如何使用批处理将文件复制并粘贴到文件夹中
【发布时间】:2015-01-16 19:59:18
【问题描述】:

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

     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

【问题讨论】:

  • 您使用 xcopy 标签表明您已经了解xcopy 命令。对于这样的事情,这绝对是一个很好的命令。到目前为止,您尝试过什么?
  • 我创建了一个批处理文件,它将数据从一个文件夹复制到另一个文件夹。但我想将该数据复制到我必须在目的地使用命令创建的子文件夹中。
  • 对不起,我粘贴了错误的文件....这是我的批处理文件:- @echo off :: variables echo 备份文件 set /P source=Enter source folder: set /P destination=Enter目标文件夹: set listfile=xcopy /L set xcopy=xcopy /S/E/V/Q/F/H %listfile% %source% %destination% echo 文件将被复制按 Enter 继续暂停 %xcopy% %source% %destination% 暂停
  • 请将代码添加到您的原始问题中,以便其他人阅读。
  • 现在我对你想要什么感到困惑。如果目标目录不存在,xcopy 将创建它。

标签: batch-file xcopy


【解决方案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

【讨论】:

    【解决方案2】:

    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%
    

    【讨论】:

      【解决方案3】:
      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-18
        • 1970-01-01
        • 1970-01-01
        • 2021-10-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多