Robocopy : 디렉토리의 내용을 이동하지만 디렉토리를 유지하는 방법 모든 내용 c:\Users\files\Desktop\test

간단한 작업 :

디렉토리의 모든 내용 c:\Users\files\Desktop\test 2c:\Users\files\Desktop\test 1

C:\admin\temp>robocopy "c:\Users\files\Desktop\test 2" "c:\Users\files\Desktop\test" *.* /S /MOVE

합리적으로 들리지만 이제는 디렉토리 c:\Users\files\Desktop\test 2도 제거됩니다. 디렉토리 자체를 제거하지 않고 컨텐츠를 이동시키는 스위치가 있습니까?



답변

네트워크 공유에서 동일한 작업을 시도했습니다.

SET MoveDirSource=\\Server\Folder
SET MoveDirDestination=Z:\Folder

다음은 Windows 7 컴퓨터에서 테스트 한 결과 및 해결책입니다.

암시:

ROBOCOPY "%MoveDirSource%" "%MoveDirDestination%" /MOVE /E

문제 : 소스 폴더를 이동합니다.

암시:

ROBOCOPY "%MoveDirSource%" "%MoveDirDestination%" /MOVE /E /XD "%MoveDirSource%"

문제 : 여전히 소스 폴더를 이동합니다.

암시:

ROBOCOPY "%MoveDirSource%" "%MoveDirDestination%" /MOV /E

문제 : 원본 폴더에 빈 폴더 구조가 남습니다.

작업 솔루션 :

MKDIR "%MoveDirDestination%"
FOR    %%i IN ("%MoveDirSource%\*") DO           MOVE /Y "%%i" "%MoveDirDestination%\%%~nxi"
FOR /D %%i IN ("%MoveDirSource%\*") DO ROBOCOPY /MOVE /E "%%i" "%MoveDirDestination%\%%~nxi"

처음 두 줄은 최상위 파일을 이동하고 세 번째 줄은 폴더를 이동합니다. 이중 %%는 배치 파일에서 사용하기위한 것이므로 명령 줄에 붙여 넣으려면 단일 백분율 표시로 변경해야합니다.

대상의 ~ nxi는 FOR SUBSTITUTION VARIABLE (FOR /? 참조)입니다. 여기서 ~ nxi는 현재 반복되는 항목의 이름과 확장을 나타냅니다.

Robocopy는 기본적으로 RETRY MILLION 번과 WAIT 30 SECONDS를 시도 할 때마다 robocopy 인수 에 / R : 1 / W : 1 을 추가 할 수 있습니다 .


답변

/ MOV 옵션을 사용해 보셨습니까?

           /MOV :: MOVe files (delete from source after copying).

F :> 로보 카피 /?


ROBOCOPY :: Windows 용 강력한 파일 복사

시작 : 금 8 월 06 일 11:51:26 2010

          Usage :: ROBOCOPY source destination [file [file]...] [options]

         source :: Source Directory (drive:\path or \\server\share\path).
    destination :: Destination Dir  (drive:\path or \\server\share\path).
           file :: File(s) to copy  (names/wildcards: default is "*.*").

::
:: Copy options :
::
             /S :: copy Subdirectories, but not empty ones.
             /E :: copy subdirectories, including Empty ones.
         /LEV:n :: only copy the top n LEVels of the source directory tree.

             /Z :: copy files in restartable mode.
             /B :: copy files in Backup mode.
            /ZB :: use restartable mode; if access denied use Backup mode.
        /EFSRAW :: copy all encrypted files in EFS RAW mode.

/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
                   (copyflags : D=Data, A=Attributes, T=Timestamps).
                   (S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

       /DCOPY:T :: COPY Directory Timestamps.

           /SEC :: copy files with SECurity (equivalent to /COPY:DATS).
       /COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
        /NOCOPY :: COPY NO file info (useful with /PURGE).

        /SECFIX :: FIX file SECurity on all files, even skipped files.
        /TIMFIX :: FIX file TIMes on all files, even skipped files.

         /PURGE :: delete dest files/dirs that no longer exist in source.
           /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).

           /MOV :: MOVe files (delete from source after copying).
          /MOVE :: MOVE files AND dirs (delete from source after copying).

 /A+:[RASHCNET] :: add the given Attributes to copied files.
 /A-:[RASHCNET] :: remove the given Attributes from copied files.

        /CREATE :: CREATE directory tree and zero-length files only.
           /FAT :: create destination files using 8.3 FAT file names only.
           /256 :: turn off very long path (> 256 characters) support.

         /MON:n :: MONitor source; run again when more than n changes seen.
         /MOT:m :: MOnitor source; run again in m minutes Time, if changed.

  /RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
            /PF :: check run hours on a Per File (not per pass) basis.

         /IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.

            /SL :: copy symbolic links versus the target.

        /MT[:n] :: Do multi-threaded copies with n threads (default 8).
                   n must be at least 1 and not greater than 128.
                   This option is incompatible with the /IPG and /EFSRAW options.
                   Redirect output using /LOG option for better performance.

::
:: File Selection Options :
::
             /A :: copy only files with the Archive attribute set.
             /M :: copy only files with the Archive attribute and reset it.
/IA:[RASHCNETO] :: Include only files with any of the given Attributes set.
/XA:[RASHCNETO] :: eXclude files with any of the given Attributes set.

/XF file [file]... :: eXclude Files matching given names/paths/wildcards.
/XD dirs [dirs]... :: eXclude Directories matching given names/paths.

            /XC :: eXclude Changed files.
            /XN :: eXclude Newer files.
            /XO :: eXclude Older files.
            /XX :: eXclude eXtra files and directories.
            /XL :: eXclude Lonely files and directories.
            /IS :: Include Same files.
            /IT :: Include Tweaked files.

         /MAX:n :: MAXimum file size - exclude files bigger than n bytes.
         /MIN:n :: MINimum file size - exclude files smaller than n bytes.

      /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
      /MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
      /MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
      /MINLAD:n :: MINimum Last Access Date - exclude files used since n.
                   (If n < 1900 then n = n days, else n = YYYYMMDD date).

            /XJ :: eXclude Junction points. (normally included by default).

           /FFT :: assume FAT File Times (2-second granularity).
           /DST :: compensate for one-hour DST time differences.

           /XJD :: eXclude Junction points for Directories.
           /XJF :: eXclude Junction points for Files.

::
:: Retry Options :
::
           /R:n :: number of Retries on failed copies: default 1 million.
           /W:n :: Wait time between retries: default is 30 seconds.

           /REG :: Save /R:n and /W:n in the Registry as default settings.

           /TBD :: wait for sharenames To Be Defined (retry error 67).

::
:: Logging Options :
::
             /L :: List only - don't copy, timestamp or delete any files.
             /X :: report all eXtra files, not just those selected.
             /V :: produce Verbose output, showing skipped files.
            /TS :: include source file Time Stamps in the output.
            /FP :: include Full Pathname of files in the output.
         /BYTES :: Print sizes as bytes.

            /NS :: No Size - don't log file sizes.
            /NC :: No Class - don't log file classes.
           /NFL :: No File List - don't log file names.
           /NDL :: No Directory List - don't log directory names.

            /NP :: No Progress - don't display percentage copied.
           /ETA :: show Estimated Time of Arrival of copied files.

      /LOG:file :: output status to LOG file (overwrite existing log).
     /LOG+:file :: output status to LOG file (append to existing log).

   /UNILOG:file :: output status to LOG file as UNICODE (overwrite existing log).
  /UNILOG+:file :: output status to LOG file as UNICODE (append to existing log).

           /TEE :: output to console window, as well as the log file.

           /NJH :: No Job Header.
           /NJS :: No Job Summary.

       /UNICODE :: output status as UNICODE.

::
:: Job Options :
::
   /JOB:jobname :: take parameters from the named JOB file.
  /SAVE:jobname :: SAVE parameters to the named job file
          /QUIT :: QUIT after processing command line (to view parameters).
          /NOSD :: NO Source Directory is specified.
          /NODD :: NO Destination Directory is specified.
            /IF :: Include the following Files.


답변

삭제하지 않으려는 디렉토리에 자리 표시 자 파일을 만든 다음 / XF를 사용하여 파일을 제외하도록 robocopy에 지시하여이를 수행 할 수 있습니다.

파일이 제외되므로 이동되지 않으며 디렉토리가 삭제되지 않습니다.

자세한 내용은 다음 사이트를 참조하십시오 : http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_24306678.html (그리고 아래로 스크롤하는 등).


답변

동일한 문제가 발생하여를 MKDIR실행 한 후 명령으로 문제를 해결 했습니다 robocopy.

주어진 폴더의 모든 내용을 이동하여 상위 폴더 만 남도록합니다. 부모 폴더를 다시 만드는 것이 어떻습니까?

물론 일부 사용자 권한 문제가있을 수 있지만 해결 될 수도 있습니다.


답변

robocopy 명령에서 제외 할 고유 플레이스 홀더 파일을 작성하십시오.

하나의 라이너는 다음과 같습니다.

echo.>>"C:\Source\.touch" && (robocopy "C:\Source" "C:\Dest" /XF ".touch" /MOVE /E & del "C:\Source\.touch")


답변

/ move 대신 / mov 스위치를 사용하십시오.


답변

“내”솔루션은 소스 폴더의 임시 폴더 내에서 파일과 폴더를 이동하는 것입니다. (임시 폴더를 자체 폴더에 복사하지 마십시오!) 그리고이 폴더를 taget 폴더로 옮긴 후.

set Source=I:\_Test\ToArchive
set target=I:\_Test\Archive
set tempFolderName=@_Copy_in_progress_Do_not_use_@
set LogFile=robocopy-result.log

robocopy.exe %source% %source%\%tempFolderName% /E /MOVE /NS /NP /v /W:0 /R:0 /LOG:%LogFile% /XD %source%\%tempFolderName%
sleep 5
robocopy.exe %source%\%tempFolderName% %target% /E /MOVE /NS /NP /v /W:0 /R:0 /LOG+:%LogFile%

임시 폴더로 “이동”하는 데 시간이 너무 많이 걸린다는 것을 알았습니다. 여기 업데이트 :

set Source=I:\_Test\ToArchive
set target=I:\_Test\Archive
set tempFolderName=@_Copy_in_progress_Do_not_use_@
set LogFile=robocopy-result.log

mkdir %source%\%tempFolderName%\
for /f "delims==" %%I IN ('dir "%source%" /B') do if NOT %%I==%tempFolderName% (move "%source%\%%I" "%source%\%tempFolderName%")
sleep 3
robocopy.exe %source%\%tempFolderName% %target% /E /MOVE /NS /NP /v /W:0 /R:0 /LOG:%LogFile%