DOS命令:用For命令遍历文件夹

Syntax:
    FOR/R [[drive:]path] %variable IN (set) DO command[command-parameters]

Description:
    Walks the directory treerooted at [drive:]path, executing the FOR statement in eachdirectory of the tree. 
  • If no directory specification is specified after /R then thecurrent directory is assumed. 
  • If set is just a single period (.) character then it will justenumerate the directory tree.
  • If set is just a single asterisk (*) character then it willjust enumerate the files.
  • If set is a single period (.) character followed by a singleasterisk (*) character then it will enumerate the sub-foldersfirstly and then files under the sub-folder recursively.
  • If set is a single asterisk (*) character followedby a single period (.) characterthen it will enumerate the files firstly then the sub-folderrecursively.
  • Wildcards characters asterisk(*) and period(.) can be repeated and the loop will also repeatedappropriately.
  • Question mark(?) is also supported and usually used to filterinterested files or sub-folders under specified folder or thecurrent folder.

Example:
@echo off
REM recursively print absolute path ofsub-folders and files under drive D:
for /R "D:\" %%s in (.,*) do(
  echo%%s
  sleep0.3
)

REM recursivelyprint absolute path of onlysub-folders under current folder
for /R %%s in (.) do (
  echo%%s
  sleep0.3
)

REM recursivelyprint absolute path of only filesunder current folder
for /R %%s in (*) do (
  echo%%s
  sleep0.3
)

REM recursivelyprint absolute path of filesunder current folder and sub-folders but only for those files withname matching pattern "list?.xul" (i.e. list0.xul orlistA.xul).

for /R %%s in (list?.xul) do(

  echo%%s

  sleep0.3

)


 

REM do the same with the above butwithout sleeping

for /R %%s in (list?.xul) do echo%%s


 

The above examples just perform echo command. However, you cando more complex commands as needed. For example, the followingexample is used to perform the following operations on all *.xulfile under the current folder and sub-folders

  • open Firefox with *.xul file
  • open *.xul files with notepad
  • sleep for 5 seconds
  • forcibly kill firefox and notepad


 

@echo off

set FIREFOX_ROOT="C:\ProgramFiles\Mozilla Firefox\"

set FIREFOX="firefox.exe"


 

for /R %%s in (*.xul) do (

  start/D%FIREFOX_ROOT% FIREFOX -chrome %%s

  start notepad%%s

  sleep 5

  taskkill /f /fi"imagename eq firefox.exe"

  taskkill /f /fi"imagename eq notepad.exe"

)

 

flvtool2.exe给某文件夹中flv文件批量插入关键帧

@echo off
for /R "H:\topntweb\topnt\topnt\"  %%s in (*.flv) do (
"H:\topntweb\topnt\topnt\FilesList\Exe\VideoTools\flvtool2.exe" -U %%s
)
pause

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值