在XCOPY /排除只是一个文件类型 [英] /exclude in xcopy just for a file type

查看:260
本文介绍了在XCOPY /排除只是一个文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,将文件从Visual Studio中复制到我的Web文件夹。我想所有的文件拷贝在我的web项目中,除了*的.cs文件。我似乎无法得到这个工作:

I have a batch file to copy over files from Visual Studio to my Web folder. I want to copy all files in my web project, EXCEPT for *.cs files. I can't seem to get this to work:

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

任何提示吗?我只是得到出口code 4,当我尝试运行此。

Any tips? I just get exit code 4 when I try to run this.

推荐答案

/排除:参数包含希望排除的文件列表的文件

The /EXCLUDE: argument expects a file containing a list of excluded files.

因此​​,创建一个名为excludedfileslist.txt包含文件:

So create a a file called "excludedfileslist.txt" containing:

.cs\

然后像这样的命令:

Then a command like this:

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

另外,您可以使用的Robocopy ,但需要安装/复制 robocopy.exe 来的机器。

Alternatively you could use Robocopy, but would require installing / copying a robocopy.exe to the machines.

这只是说明匿名评论编辑该解决方案还排除CSS文件!

An anonymous comment edit which simply stated "This Solution exclude also css file!"

这是真正的创造了excludedfileslist.txt文件仅包含:

This is true creating a "excludedfileslist.txt file contain just:

.cs

(注意最后没有反斜线)

(note no backslash on the end)

也将排除所有的以下内容:

Will also exclude all of the following:


  • file1.cs

  • file2.css

  • dir1.cs \\ file3.txt

  • DIR2 \\ anyfile.cs.something.txt

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

有时候人不阅读或理解XCOPY命令的帮助下,这里是我想强调一个项目:

Sometimes people don't read or understand the XCOPY command's help, here is an item I would like to highlight:

使用/排除


      
  • 在每个文件的单独一行每个字符串列表。如果任何所列出的串的匹配的文件的绝对路径的任何部分可被复制时,该文件然后从复制过程中排除。例如,如果你指定字符串\\的Obj \\,您排除与obj目录下的所有文件。如果指定字符串.OBJ,您排除所有文件与.obj扩展名。

  •   
  • List each string in a separate line in each file. If any of the listed strings match any part of the absolute path of the file to be copied, that file is then excluded from the copying process. For example, if you specify the string "\Obj\", you exclude all files underneath the Obj directory. If you specify the string ".obj", you exclude all files with the .obj extension.

作为例子指出它排除与.obj扩展名的所有文件,但它并没有说明,它也排除命名的文件或目录文件1 .obj.tmp dir.obj.output \\ example2.txt

As the example states it excludes all files with the .obj extension but it doesn't state that it also exclude files or directories named file1.obj.tmp or dir.obj.output\example2.txt.

有大约被排除的.css 文件也是一个办法,改变excludedfileslist.txt,以仅包含:

There is a way around .css files being excluded also, change the "excludedfileslist.txt" to contain just:

.cs\

(注意的反斜线)。

(note the backslash on the end).

下面是供您参考一个完整的测试序列:

Here is a complete test sequence for your reference:

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

此测试已经完成Windows 7的命令行上。

This test was completed on a Windows 7 command line.

请注意,在最后一个例子不排除 \\ SRC \\ dir1.file4.cs.txt 这可能是也可能不是意外适合你。

Note that in the last example does exclude .\src\dir1.file4.cs.txt which may or may not be unexpected for you.

这篇关于在XCOPY /排除只是一个文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆