從 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

當您對批次檔的運作效果感到滿意時,請刪除echodo 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>

進一步閱讀

相關內容