每隔五个字符串就会批量暂停

时间:2014-10-11 21:00:39

标签: file batch-file

我的问题是我做了一个显示目录中所有文件的东西,但因为它太长而且线太多,我决定让它说例如它将暂停的每五行。

较小版本的代码是: for /r %%a in (*) do echo %%a 所以我猜你有个主意吗?

2 个答案:

答案 0 :(得分:0)

为什么不使用为此设计的more命令。它执行的是屏幕而不是5(除非您使用p 5命令)。

C:\Users\User>more /?
Displays output one screen at a time.

MORE [/E [/C] [/P] [/S] [/Tn] [+n]] < [drive:][path]filename
command-name | MORE [/E [/C] [/P] [/S] [/Tn] [+n]]
MORE /E [/C] [/P] [/S] [/Tn] [+n] [files]
[drive:][path]filename  Specifies a file to display one
                        screen at a time.

command-name            Specifies a command whose output
                        will be displayed.

/E      Enable extended features
/C      Clear screen before displaying page
/P      Expand FormFeed characters
/S      Squeeze multiple blank lines into a single line
/Tn     Expand tabs to n spaces (default 8)

        Switches can be present in the MORE environment
        variable.

+n      Start displaying the first file at line n

files   List of files to be displayed. Files in the list
        are separated by blanks.

If extended features are enabled, the following commands
are accepted at the -- More -- prompt:

P n     Display next n lines
S n     Skip next n lines
F       Display next file
Q       Quit
=       Show line number
?       Show help line
<space> Display next page
<ret>   Display next line

在for循环使用set /a和!var中执行此操作!类型变量(阅读所有set&#39; s帮助)。请参阅For /?setlocal /?中的帮助。

答案 1 :(得分:0)

就像@Noodles说MORE或:

编辑:

@echo off
setlocal enabledelayedexpansion
set /a $C=1
for /r %%a in (*) do (
  IF !$C!==5 (
     echo.
     pause >nul
     set /a $C=1)
  echo %%a
  set /a $C+=1)