Windowsbatch file脚本将每个第十个文件从一个文件夹复制到另一个文件夹

我在一个目录中有许多文本文件,我想根据文件的名称/字母顺序select每十个文件(即10,20,30,40等文件),并将它们复制到另一个文件夹中。

例如:

我有一个文件夹C:\文件\源\包含的文件:

12.txt 16.txt 2007.txt 2008.txt 200865.txt 2008616263.txt a.txt across.txt addition.txt album.txt American.txt an.txt and.txt April.txt article.txt Artist.txt at.txt Award.txt Awards.txt Awards64.txt Bad.txt Best.txt breakout.txt by.txt Canada.txt categories.txt Collaboration59.txt Dance.txt Dark.txt December.txt Diva.txt Duo.txt earned.txt embarked.txt Entertainment.txt entitled.txt Europe60.txt Favorite.txt Female.txt Fiasco.txt first.txt five.txt for.txt four.txt Girl.txt Glow.txt Gone.txt Good.txt Grammy.txt Group.txt he.txt headlining.txt her.txt in.txt including.txt Kanye.txt kicked.txt Lupe.txt Margeaux.txt Monster.txt MTV.txt Music.txt NERD.txt nominated.txt nominations.txt of.txt off.txt on.txt or.txt other.txt Performance.txt PopRock.txt R&B.txt RapSung.txt receiving.txt Record.txt Recording.txt referred.txt Rihanna.txt second.txt September.txt several.txt she.txt shows.txt Single.txt Song.txt SoulR&B.txt States.txt success.txt support.txt the.txt then.txt to.txt tour.txt United.txt Video.txt was.txt Watson.txt Weekly.txt West.txt which.txt winning.txt with.txt won.txt wrote.txt Year.txt Year58.txt 

我想将album.txt,Awards64.txt,December.txt,Fiasco.txt,Group.txt,Monster.txt,other.txt,second.txt,support.txt和West.txt文件复制到文件夹C:\文件\输出\

我如何编写一个可以实现这个目标的batch file

只需遍历文件列表即可:

 @echo off set Counter=0 for %%f in (*.txt) do call :p "%%f" goto :eof :p set /a Counter+=1 set /a X=Counter %% 10 if %X%==0 copy %1 C:\Documents\Output goto :eof 

应该工作,但不能测试,因为我(正确)没有权限写入根目录;-)

为了适应每第八个文件左右,只需改变set /a X=Counter %% 10

请注意,虽然NTFS输出文件列表排序这是不同的排序,你会从资源管理器(或任何尊重区域和语言选项中设置的排序方法)。

你能改变文件名吗? 简单的解决办法是标记每个第10个文件,具体取决于您的输出创建它们。 然后用通配符和标记复制它们。

添加一些修改,使从一个文件夹几个磁盘:脏,但工作:)。 对于每个磁盘“offs”,var和target文件夹都必须更改。 其他在原来的脚本

 @echo off set Counter=0 set offs=0 for %%f in (*.mp3) do call :p "%%f" goto :eof :p set /a c2=Counter-offs set /a X=c2 %% 8 set /a Counter+=1 if %X%==0 copy %1 d:\avtcd_tgt\cd1 goto :eof