windows批处理文件脚本将每十个文件从一个文件夹复制到另一个文件夹 [英] windows batch file script to copy every tenth file from a folder to another folder

查看:28
本文介绍了windows批处理文件脚本将每十个文件从一个文件夹复制到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have numerous text files in a directory and I want to select every tenth file (i.e. 10th, 20th, 30th, 40th, etc. file) according to name/alphabetical arrangement of the files and copy them to another folder.

For example:

I have a folder C:documentssource that contains the files:

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

I want the files album.txt, Awards64.txt, December.txt, Fiasco.txt, Group.txt, Monster.txt, other.txt, second.txt, support.txt and West.txt copied to the folder C:documentsoutput

How do I write a batch file that can achieve this goal?

解决方案

Just count while iterating through the list of files:

@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

Should work, but cannot test since I (rightfully) have no permissions to write into the root directory ;-)

To adapt to every eighth file or so, just change the 10 in set /a X=Counter %% 10.

Note though, that while NTFS outputs file lists sorted this is not the same sorting you'd get from Explorer (or anything else that respects the sorting method set in the regional and language options).

这篇关于windows批处理文件脚本将每十个文件从一个文件夹复制到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆