@echo off for /f "tokens=1" %%i in ("1 2 3 4 5") do ( echo %%i ) 只输出了一个tokens=1
时间: 2023-12-06 15:40:16 浏览: 37
这个问题是因为命令行默认使用空格作为分隔符,所以 "1 2 3 4 5" 被解析成了一个参数,而不是多个参数。可以尝试将分隔符改为其他字符,比如逗号:
```
@echo off
for /f "tokens=1 delims=," %%i in ("1,2,3,4,5") do (
echo %%i
)
```
这样就可以正确输出 1 到 5 的数字了。
相关问题
for /f "tokens=1" %%i in ("1 2 3 4 5") do
This is a batch command that loops through the numbers 1 to 5 and assigns each number to the variable "%%i" using the "tokens" parameter. The "do" keyword indicates the start of the loop body, which can contain one or more commands. Here's an example of how this command can be used:
```
@echo off
for /f "tokens=1" %%i in ("1 2 3 4 5") do (
echo %%i
)
```
This will output the numbers 1 to 5 on separate lines.
@echo offsetlocal EnableDelayedExpansionset dirPath=<您的目录路径>for /f "tokens=* delims=" %%a in ('dir /b /a-d "%dirPath%"') do ( set fileSize=%%~za set /a fileSizeKB=!fileSize!/1024 echo %%a !fileSizeKB! KB)pause
这段代码是一个 Windows 批处理脚本,用于输出指定目录下所有文件的文件名和文件大小(单位为 KB)。
脚本中的变量 `dirPath` 可以根据你的需求替换为指定的目录路径。
`for /f "tokens=* delims=" %%a in ('dir /b /a-d "%dirPath%"') do` 这一行代码是一个 for 循环,用于遍历指定目录下所有非目录文件。`dir /b /a-d "%dirPath%"` 用于获取指定目录下所有非目录文件的文件名,`/b` 参数表示只输出文件名而不显示其他信息,`/a-d` 参数表示只输出非目录文件。
`set fileSize=%%~za` 这一行代码用于获取文件大小,`%%~za` 表示获取当前循环到的文件的文件大小。`set /a fileSizeKB=!fileSize!/1024` 将文件大小转换为 KB 并存储到变量 `fileSizeKB` 中。
`echo %%a !fileSizeKB! KB` 输出当前循环到的文件名和文件大小。
最后的 `pause` 语句用于暂停脚本的执行,等待用户按下任意键继续。