Windows 8.1의 폴더에서 마지막 N개 파일 이동

Windows 8.1의 폴더에서 마지막 N개 파일 이동

저는 궁금합니다. Windows 8.1에서 마지막 N개 파일을 폴더에서 다른 폴더로 이동하는 프로그램을 작성하는 것 외에 멋지고 우아한 방법이 있습니까?

편집하다: N은 예를 들어 100이고 파일은 이름별로 정렬됩니다.

답변1

폴더에서 마지막 N개 파일을 어떻게 이동합니까?

N은 예를 들어 100이고 파일은 이름별로 정렬됩니다.

다음 배치 파일(test.cmd)을 사용합니다.

@echo off
rem parameters
rem %1 number of files to move
rem %2 source directory
rem %3 target directory
Setlocal EnableDelayedExpansion
rem initialise number of files
set count=0
rem count files
for /f "delims=" %%a in ('dir %2 /a-d /b /O:N') do @(set /a count+=1 >nul)
rem set number of files to skip (not move)
set /a "skip=count-%1"
rem move the files
for /f "skip=%skip% delims=" %%a in ('dir %2 /a-d /b /O:N') do echo move %2\%%a %3\%%a

배치 파일이 만족스럽게 작동하면 echo을 제거하십시오 .do echo move...

용법:

test N Source Target

어디:

  • N이동할 파일 수
  • Source소스 디렉토리
  • Target대상 디렉토리

예:

C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is C8D0-DF1E

 Directory of C:\test

31/05/2015  11:31    <DIR>          .
31/05/2015  11:31    <DIR>          ..
26/05/2015  18:20               117 address.out
26/05/2015  18:16               265 data.txt
31/05/2015  11:25    <JUNCTION>     junction [f:\test]
31/05/2015  11:31    <DIR>          sub
31/05/2015  18:16               449 test.cmd
               3 File(s)            831 bytes
               4 Dir(s)  95,480,258,560 bytes free

C:\test>test 1 . c:\temp
move .\test.cmd c:\temp\test.cmd
C:\test>

추가 읽기

관련 정보