windows的bat脚本连接字符串并保存到一个临时变量中

假设我有一个文件目录,里面有很多sql文件,我需要遍历这些sql文件并获取他们的文件名,将文件名字符串连接起来形成一个列表存储到一个临时变量中,那么应该怎么做呢?

在这里插入图片描述
可以参考下面的脚本

@echo off
setlocal enabledelayedexpansion
set myvar=the list: 
for /r %%i In (*.sql) DO set myvar=!myvar! %%i,
echo %myvar%

最终会输出一个连接起来的列表,需要注意的是windows临时变量存储最多只能保存8192bytes大小。
在这里插入图片描述

连接两个Remarks变量

比如我要批量把*.sql命名为*_old.sql那么应该怎么做呢?
其实@fname 和 @ext 这种Remarks变量可以直接连接的

forfiles /S /M *.sql /C "CMD /C REN @path @fname_old.@ext"

Remarks

  • Forfiles is most commonly used in batch files.
  • Forfiles /s is similar to dir /s.
  • You can use the following variables in the command string as specified by the /c command-line option.
    Variable Description
    @FILE File name.
    @FNAME File name without extension.
    @EXT File name extension.
    @PATH Full path of the file.
    @RELPATH Relative path of the file.
    @ISDIR Evaluates to TRUE if a file type is a directory. Otherwise, this variable evaluates to FALSE.
    @FSIZE File size, in bytes.
    @FDATE Last modified date stamp on the file.
    @FTIME Last modified time stamp on the file.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值