Nice programing

/ 파일 유형에 대해서만 xcopy에서 제외

nicepro 2020. 11. 20. 09:39
반응형

/ 파일 유형에 대해서만 xcopy에서 제외


Visual Studio에서 내 웹 폴더로 파일을 복사 할 배치 파일이 있습니다. * .cs 파일을 제외하고 웹 프로젝트의 모든 파일을 복사하고 싶습니다. 이 작업을 수행 할 수없는 것 같습니다.

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

팁이 있습니까? 이것을 실행하려고 할 때 종료 코드 4가 나타납니다.


/EXCLUDE:인수는 제외 된 파일의 목록이 포함 된 파일을 기대하고있다.

따라서 다음을 excludedfileslist.txt포함 하는 파일을 만듭니다 .

.cs\

다음과 같은 명령 :

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

또는 Robocopy를 사용할 수 있지만 robocopy.exe머신에 a 설치 / 복사해야 합니다.

최신 정보

단순히 "이 솔루션은 CSS 파일도 제외합니다!"라는 익명의 주석 편집

이것은 사실입니다 excludedfileslist.txt.

.cs

(끝에 백 슬래시 없음)

다음 항목도 모두 제외됩니다.

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

때때로 사람들은 XCOPY 명령의 도움말을 읽거나 이해하지 못합니다. 여기에 강조하고 싶은 항목이 있습니다.

/ exclude 사용

  • 각 파일의 개별 줄에 각 문자열을 나열합니다. 나열된 문자열 중 하나라도 복사 할 파일의 절대 경로의 일부와 일치하면 해당 파일은 복사 프로세스에서 제외됩니다. 예를 들어 "\ Obj \"문자열을 지정하면 Obj 디렉터리 아래의 모든 파일을 제외합니다. 문자열 ".obj"를 지정하면 확장자가 .obj 인 모든 파일이 제외됩니다.

예 "는 .OBJ 확장명을 가진 모든 파일"그것을 제외를 주장하지만, 그것은 또한 제외 파일이나 디렉토리 이름을 그 상태로하지 않는 file1.obj.tmpdir.obj.output\example2.txt.

.css제외되는 파일을 우회하는 방법 도 있습니다. 다음 excludedfileslist.txt을 포함 하도록 파일을 변경하십시오 .

.cs\

(끝의 백 슬래시에 유의하십시오).

다음은 참조를위한 전체 테스트 순서입니다.

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 명령 줄에서 완료되었으며 Windows 10 "10.0.14393"에서 다시 테스트되었습니다.

마지막 예에서는 .\src\dir2.cs\file5.txt예상치 못한 상황을 제외 하고 있습니다.


제 경우에는 xcopy가 첫 번째 줄을 무시했기 때문에 두 번째 줄에서 제외 확장 목록을 시작해야했습니다.


excludefileslist.txt에서 * .cs를 .cs로 변경하십시오.


여러 파일 형식을 제외하려면 '+'를 사용하여 다른 목록을 연결할 수 있습니다. 예를 들면 :

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/

참고URL : https://stackoverflow.com/questions/4252176/exclude-in-xcopy-just-for-a-file-type

반응형