덮어 쓰지 않고 파일 복사
명령 줄에서 "디렉토리 A에서 디렉토리 B로 모든 파일을 복사합니다.하지만 파일이 디렉토리 B에 이미 존재한다면 어떤 파일이 더 최신인지에 상관없이 덮어 쓰지 마십시오."라고 말하는 방법을 찾을 수없는 것 같습니다. , 나에게 메시지를 표시하지 않습니다. "
나는 copy, move, xcopy & robocopy를 겪었고, 내가 얻을 수있는 가장 가까운 것은 당신이 robocopy에게 "A를 B로 복사하되 이전 파일로 새로운 파일을 덮어 쓰지 말라"라고 말할 수 있다는 것입니다.하지만 그것은 저에게 효과가 없습니다. . xxcopy를 살펴 보았지만 다른 SVN 사용자가 빌드를 수행하기 위해 해당 도구를 설치해야하는 Visual Studio 빌드 후 이벤트에 대한 타사 종속성을 원하지 않기 때문에 삭제했습니다.
Visual Studio 2010의 빌드 후 이벤트에 명령 줄을 추가하여 새 EF 모델 개체에 대한 T4 템플릿 에서 생성 된 파일이 해당 파일이 속한 프로젝트 폴더에 배포되지만 기존 개체에 대해서는 다시 생성 된 파일을 배포하려고합니다. 잠재적으로 편집 된 대상 파일을 덮어 쓰지 마십시오.
T4 템플릿이 재생성되기 때문에 소스 파일은 항상 최신 상태이며 "newer"스위치를 안정적으로 사용할 수 없다고 생각합니다.
가능한 항목에 대해 부분 클래스를 사용하지만 부분 클래스를 사용할 수없는 다른 항목이 생성됩니다 (예 : 기본 EditorTemplate 또는 DisplayTemplate * .ascx 파일 생성).
비슷한 문제를 해결 한 사람이 있습니까?
For %F In ("C:\From\*.*") Do If Not Exist "C:\To\%~nxF" Copy "%F" "C:\To\%~nxF"
ROBOCOPY , 또는 "강력한 파일 복사"명령 줄 디렉터리 복제 명령입니다. Windows NT 4.0부터 Windows Resource Kit의 일부로 제공되었으며 Windows Vista, Windows 7 및 Windows Server 2008의 표준 기능으로 도입되었습니다.
robocopy c:\Sourcepath c:\Destpath /E /XC /XN /XO
자세히 설명하려면 (Hydrargyrum, HailGallaxar 및 Andy Schmidt 답변 사용) :
/E
Robocopy는 빈 디렉터리를 포함하여 하위 디렉터리를 반복적으로 복사합니다./XC
타임 스탬프는 같지만 파일 크기는 다른 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다./XN
대상 디렉토리의 복사본보다 새로운 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다./XO
대상 디렉토리의 사본보다 오래된 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다.
Changed, Older 및 Newer 클래스를 제외하면 Robocopy는 스크립팅 환경을로드 할 필요없이 원본 포스터가 원하는대로 정확하게 수행합니다.
참조 : Technet , Wikipedia
다운로드 위치 : Microsoft 다운로드 링크 (링크는 2016 년 3 월 30 일에 마지막으로 확인 됨)
벨리 사리우스의 해결책이 좋습니다.
약간 간결한 대답에 대해 자세히 설명하려면 다음을 수행하십시오.
/E
Robocopy는 빈 디렉터리를 포함하여 하위 디렉터리를 반복적으로 복사합니다./XC
타임 스탬프는 같지만 파일 크기는 다른 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다./XN
소스 디렉토리의 사본보다 새로운 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다./XO
소스 디렉토리의 사본보다 오래된 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다.
Changed, Older 및 Newer 클래스를 제외하면 Robocopy는 스크립팅 환경을로드 할 필요없이 원본 포스터가 원하는대로 정확하게 수행합니다.
이것을 시도 할 수 있습니다.
echo n | copy /-y <SOURCE> <DESTINATION>
-y
덮어 쓰기 전에 프롬프트를 표시하고 n을 이러한 모든 질문에 파이프 할 수 있습니다. 따라서 이것은 본질적으로 존재하지 않는 파일을 복사합니다. :)
다음은 배치 파일 형식입니다.
@echo off
set source=%1
set dest=%2
for %%f in (%source%\*) do if not exist "%dest%\%%~nxf" copy "%%f" "%dest%\%%~nxf"
나는 내 자신의 테스트에서 무언가를 명확히하고 싶습니다.
@Hydrargyrum은 다음과 같이 썼습니다.
- / XN은 원본 디렉터리의 복사본보다 새로운 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다.
- / XO는 원본 디렉터리의 복사본보다 오래된 기존 파일을 제외합니다. Robocopy는 일반적으로이를 덮어 씁니다.
이것은 실제로 거꾸로입니다. XN은 "최신 파일 제외"를 수행하지만 대상 디렉토리 의 사본보다 최신 파일은 제외합니다 . XO는 "이전 항목 제외"를 수행하지만 대상 디렉토리 의 복사본보다 오래된 파일은 제외합니다 .
물론 항상 자신의 테스트를 수행하십시오.
xcopy로이 작업을 수행하는 이상한 방법이 있습니다.
echo nnnnnnnnnnn | xcopy /-y source target
Just include as many n's as files you're copying, and it will answer n to all of the overwrite questions.
robocopy src dst /MIR /XX
/XX : eXclude "eXtra" files and dirs (present in destination but not source). This will prevent any deletions from the destination. (this is the default)
Robocopy can be downloaded here for systems where it is not installed already. (I.e. Windows Server 2003.)
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17657 (no reboot required for installation)
Remember to set your path to the robocopy exe. You do this by right clicking "my computer"> properties>advanced>"Environment Variables", then find the path system variable and add this to the end: ";C:\Program Files\Windows Resource Kits\Tools" or wherever you installed it. Make sure to leave the path variable strings that are already there and just append the addtional path.
once the path is set, you can run the command that belisarius suggests. It works great.
It won't let me comment directly on the incorrect messages - but let me just warn everyone, that the definition of the /XN and /XO options are REVERSED compared to what has been posted in previous messages.
The Exclude Older/Newer files option is consistent with the information displayed in RoboCopy's logging: RoboCopy will iterate through the SOURCE and then report whether each file in the SOURCE is "OLDER" or "NEWER" than the file in the destination.
Consequently, /XO will exclude OLDER SOURCE files (which is intuitive), not "older than the source" as had been claimed here.
If you want to copy only new or changed source files, but avoid replacing more recent destination files, then /XO is the correct option to use.
A simple approach would be to use the /MIR option, to mirror the two directories. Basically it will copy only the new files to destination. In next comand replace source and destination with the paths to your folders, the script will search for any file with any extensions.
robocopy <source directory> <destination directory> *.* /MIR
This is what has worked for me. I use this to "add" files over to the other drive, with no overwrites.
Batch file: robocopy-missingfiles.bat
@echo off
echo Copying
echo "%1"
echo to "%2"
echo.
echo Press Cntr+C to abort
Pause
echo.
@echo on
robocopy %1 %2 /Xo /XN /XC /J /SL /S /MT:8 /R:1 /W:1 /V /DCOPY:DAT /ETA /COPY:DATO /FFT /A-:SH /XD $RECYCLE.BIN "System Volume Information"
Example:
robocopy-missingfiles.bat f:\Working-folder\ E:\Backup-folder\
Do test before implementation.
참고URL : https://stackoverflow.com/questions/4228807/copy-files-without-overwrite
'developer tip' 카테고리의 다른 글
프로그래밍 방식으로 UIView의 사용자 정의 테두리 색상을 설정하는 방법은 무엇입니까? (0) | 2020.09.06 |
---|---|
Volley Request에서 사용자 지정 헤더를 설정하는 방법 (0) | 2020.09.06 |
UIButton이 콘텐츠 모드 설정을 수신하지 않습니까? (0) | 2020.09.06 |
어떤 리눅스 쉘 명령이 문자열의 일부를 반환합니까? (0) | 2020.09.06 |
PHP에서 sqlite3를 활성화하는 방법은 무엇입니까? (0) | 2020.09.06 |