2014-04-24 4 views
0

파일을 c : \ prueba1에서 c : \ prueba99로 이동해야하지만 원본 디렉토리의 모든 파일을 비교하는 방법을 알지 못합니다 (c : \ prueba99)을 사용하여 디렉토리의 마지막 수정 된 파일을 제외하고 디렉토리의 모든 파일을 이동합니다. 나는 InstallDate, LastModified를 가진 wmic 명령을 알고 있지만, 변수를 설정하고 읽은 한 파일이 마지막으로 수정되었음을 알기 위해 비교할 ms-dos 구문을 알지 못합니다.마지막으로 수정 한 파일을 제외한 모든 파일을 새 디렉토리에 복사하십시오.

예를 발견했습니다 :

for /f "delims=" %%A in ('wmic datafile where "drive = 'c:' and path='\\windows\\'" 
    get LastModified^,Name /format:table^|find ":"^|sort /r') do @echo %%A 

그리고 데이터 파일 이름 만 나열하고 파일 자체는 표시하지 않으므로 결과가 수정되지 않았습니다.

이 내 수정 된 버전입니다 :

for /f "skip=1 delims=" %%A in ('wmic datafile where "drive = 'c:' and path='\\prueba1\\'" 
    get LastModified^,Name /format:table^|find ":"^| sort/r') do move (%%A) c:\prueba99 

답변

0
for /f "skip=1 delims=" %%a in ('dir /b /tw /o-d /a-d c:\prueba1\*.*' 
) do move "c:\prueba1\%%a" "c:\prueba99" 

dir 명령을 생성 날짜 순서를 내림차순으로 파일을 가져, 그래서 처음 최신입니다. for 명령은 첫 번째 파일을 건너 뛰고 파일을 대상 폴더로 이동하여이 목록을 반복합니다.

+0

무엇을하지 말 일세/B/TW의/외경/광고 의미? –

+0

@MethodistMX, 파일 이름 ('/ b') 만 날짜 정렬 ('/ tw')에 수정 날짜 사용, 날짜 내림차순으로 정렬 ('/ o-d'), 디렉토리 ('/ a-d') –

0

마지막으로 수정 된 파일 GE하는 방법 :

@echo off 
set $path=c:\prueba99 

for /f %%a in ('dir/b/a-d/o-d "%$path%"') do (
set $Last=%%a 
goto:next) 

:next 
echo Last modified : [ %$Last% ] 
0

이 당신을 위해 작동해야하며, 그것은 또한 당신이 원하는만큼 NEWEST 파일을 삭제 할 수 있습니다 (귀하의 경우에 내가 1을 촬영했습니다) :

@echo off 
setlocal 

:: change the next two statements to match what you want 
set srcdir=C:\prueba1 
set tgtdir=C:\prueba99 
if not exist %tgtdir%\*.* md %tgtdir% 
set ctr=0 
for /f "tokens=*" %%a in ('dir "%srcdir%" /o-d /b') do call :maybemove "%%a" 
set /a ctr-=3 
echo %~n0: %ctr% files were moved from %srcdir% to %tgtdir% 
endlocal 
goto :eof 

::-------------------- 

:maybemove 
:: increment counter and bypass the ONE newest file 
set /a ctr+=1 
if %ctr% leq 1 goto :eof 
:: remove the double-quotes from the front and back of the filename 
set fn=%~1 
:: perform the move 
move /y "%srcdir%\%fn%" "%tgtdir%" 
goto :eof 
관련 문제