代码之家  ›  专栏  ›  技术社区  ›  Matt Dell

/仅针对文件类型排除在Xcopy中

  •  58
  • Matt Dell  · 技术社区  · 15 年前

    xcopy /r /d /i /s /y /exclude:".cs" C:\dev\apan C:\web\apan
    

    4 回复  |  直到 7 年前
        1
  •  107
  •   Dean Taylor    7 年前

    这个 /EXCLUDE: 参数需要包含排除文件列表的文件。

    所以创建一个名为 excludedfileslist.txt

    .cs\
    

    这样的命令:

    xcopy /r /d /i /s /y /exclude:excludedfileslist.txt C:\dev\apan C:\web\apan
    

    Robocopy ,但需要安装/复制 robocopy.exe 到机器上。

    更新

    一个匿名注释编辑,它简单地说“这个解决方案也排除了CSS文件!”

    excludedfileslist.txt

    .cs
    

    (注意末尾没有反斜杠)

    • file1.cs
    • file2.css
    • dir1.cs\file3.txt
    • dir2\anyfile.cs.something.txt

    有时人们不阅读或不理解xcopy命令的帮助,以下是我要强调的一项:

    使用/排除

    • 在要复制的文件的绝对路径中,该文件将从复制过程中排除。例如,如果指定字符串“\obj”,则排除obj目录下的所有文件。如果指定字符串“.obj”,则排除扩展名为.obj的所有文件。

    如示例所述,它排除了“所有扩展名为.obj的文件”,但它没有说明它也排除了名为 file1.obj.tmp dir.obj.output\example2.txt

    有条路可以走 .css excludedfileslist.txt 要仅包含的文件:

    (注意末尾的反斜杠)。

    C:\test1>ver
    
    Microsoft Windows [Version 6.1.7601]
    
    C:\test1>md src
    C:\test1>md dst
    C:\test1>md src\dir1
    C:\test1>md src\dir2.cs
    C:\test1>echo "file contents" > src\file1.cs
    C:\test1>echo "file contents" > src\file2.css
    C:\test1>echo "file contents" > src\dir1\file3.txt
    C:\test1>echo "file contents" > src\dir1\file4.cs.txt
    C:\test1>echo "file contents" > src\dir2.cs\file5.txt
    
    C:\test1>xcopy /r /i /s /y .\src .\dst
    .\src\file1.cs
    .\src\file2.css
    .\src\dir1\file3.txt
    .\src\dir1\file4.cs.txt
    .\src\dir2.cs\file5.txt
    5 File(s) copied
    
    C:\test1>echo .cs > excludedfileslist.txt
    C:\test1>xcopy /r /i /s /y /exclude:excludedfileslist.txt .\src .\dst
    .\src\dir1\file3.txt
    1 File(s) copied
    
    C:\test1>echo .cs\ > excludedfileslist.txt
    C:\test1>xcopy /r /i /s /y /exclude:excludedfileslist.txt .\src .\dst
    .\src\file2.css
    .\src\dir1\file3.txt
    .\src\dir1\file4.cs.txt
    3 File(s) copied
    

    .\src\dir2.cs\file5.txt

        2
  •  7
  •   VLKxCOOL    12 年前

    在我的例子中,我必须从第二行开始一个排除扩展列表,因为Xcopy忽略了第一行。

        3
  •  5
  •   Taiwo    13 年前

        4
  •  1
  •   Leopoldo Sanczyk    11 年前

    对于排除多个文件类型,可以使用“+”连接其他列表。例如:

    xcopy /r /d /i /s /y /exclude:excludedfileslist1.txt+excludedfileslist2.txt C:\dev\apan C:\web\apan
    

    来源: http://www.tech-recipes.com/rx/2682/xcopy_command_using_the_exclude_flag/

    推荐文章