我在目录中有很多文本文件,我想根据文件的名称/字母顺序排列选择每个第十个文件(即第10,第20,第30,第40等文件)并将它们复制到另一个文件夹。 / p>
例如:
我有一个文件夹C:\ documents \ source \,其中包含文件:
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:\文件\输出\
如何编写可以实现此目标的批处理文件?
答案 0 :(得分:5)
在迭代文件列表时计算:
@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
应该可以工作,但无法测试,因为我(理所当然)没有权限写入根目录; - )
要适应每八个文件左右,只需更改10
中的set /a X=Counter %% 10
。
但请注意,虽然NTFS输出的文件列表已排序,但这与您从资源管理器(或其他任何尊重区域和语言选项中设置的排序方法)的排序不同。
答案 1 :(得分:1)
您可以更改文件名吗?简单的解决方案是根据您的输出创建它们来标记每个第10个文件。然后用通配符和标记复制它们。
答案 2 :(得分:-1)
为从一个文件夹制作几个磁盘添加了一些修改: 脏,但工作:)。对于每个磁盘“offs”,必须更改var和目标文件夹。其他如原始剧本
@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