我在一个目录中有许多文本文件,我想根据文件的名称/字母顺序选择每10个文件(即第10个,第20个,第30个,第40个等文件),并将它们复制到另一个文件夹。
例如:我有一个文件夹C:documentssource,包含以下文件:
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、ward64 .txt、December.txt、Fiasco.txt、Group.txt、Monster.txt、other.txt、second.txt、support.txt和West.txt文件拷贝到文件夹C:documentsoutput
我如何写一个批处理文件,可以实现这个目标?
在遍历文件列表时进行计数:
@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:DocumentsOutput
goto :eof
应该可以工作,但无法测试,因为我(正确地)没有权限写入根目录;-)
要适应每八个文件左右,只需更改set /a X=Counter %% 10
中的10
。
请注意,虽然NTFS输出的文件列表已排序,但这与您从资源管理器(或任何尊重区域和语言选项中设置的排序方法的其他东西)中获得的排序不同。
可以更改文件名吗?简单的解决方案是根据您的输出所创建的文件标记每10个文件。然后用通配符和你的标记复制它们。
为从一个文件夹中创建两个磁盘添加了一些修改:很脏,但很有效:)。对于每个磁盘"off",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_tgtcd1
goto :eof