Windows批处理脚本以查找免费文件名

sean.net

我必须编写一个脚本,将文件复制到备份文件夹。如果文件名已被使用,它将添加索引。我似乎无法正常工作。变量tmpfile似乎永远不会带有索引计数器。我究竟做错了什么?该脚本如下。

谢谢,肖恩

set srcdir=%~dp0
set oldxladir=%srcdir%OldXLAs

if not exist %oldxladir% mkdir %oldxladir%

set pathstart=C:\Documents and Settings\
set username=%USERNAME%
set pathend=\Application Data\Microsoft\Excel\XLSTART\
set pattern=groovy*.xla

set xladir=%pathstart%%username%%pathend%
set xlapattern="%pathstart%%username%%pathend%%pattern%"

for %%f in (%xlapattern%) do (
    set filename=%%~nxf
    set srcfile=%xladir%%filename%
    set destfile=%oldxladir%\%filename%
    set tmpfile=%destfile%

    set /a index=1
    :loop
    if exist tmpfile (
        set /a index+=1
        echo %index%
        set tmpfile=%destfile%%index%
        goto :loop
    )

    echo %tmpfile%
    move "%srcfile%" "%tmpfile%"
)
LS_ᴅᴇᴠ
SETLOCAL ENABLEDELAYEDEXPANSION
set srcdir=%~dp0
set oldxladir=%srcdir%OldXLAs

if not exist %oldxladir% mkdir %oldxladir%

set pathstart=C:\Documents and Settings\
set username=%USERNAME%
set pathend=\Application Data\Microsoft\Excel\XLSTART\
set pattern=groovy*.xla

set xladir=%pathstart%%username%%pathend%
set xlapattern="%pathstart%%username%%pathend%%pattern%"

for %%f in (%xlapattern%) do (
    set filename=%%~nxf
    set srcfile=%xladir%!filename!
    set destfile=%oldxladir%\!filename!
    set tmpfile=!destfile!

    set /a index=1
    :loop
    if exist !tmpfile! (
        set /a index+=1
        echo !index!
        set tmpfile=!destfile!!index!
        goto :loop
    )

    echo !tmpfile!
    move "!srcfile!" "!tmpfile!"
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

创建唯一的文件名Windows批处理

批处理脚本以查找特定的目录名称

批处理脚本在带括号的文件名上失败

批处理文件查找包含子字符串的文件名

双击时将文件名传递给Windows批处理(.bat)脚本,以便它将以八度运行

使用批处理脚本在文件名后附加日期

使用批处理脚本从文件名中删除日期

批处理文件在文件名中查找重复模式,然后进行处理

文件名与模式列表不匹配时批处理脚本删除文件

Windows批处理脚本:如何从ftype命令输出中仅提取文件名

Windows批处理文件名操作

批处理脚本以在子文件夹中查找文件夹并获取文件夹路径

如何在Windows命令行中的文件名和批处理脚本中使用日语字符?

批处理脚本以更改txt文件

编写批处理脚本以查找子目录

文件名与模式匹配时批处理脚本删除文件

将文件名插入多个子文件夹中的文件的批处理脚本

Windows批处理脚本替换文件名中的单词

请帮助编写脚本以查找文件名最长的文件

如何使用批处理脚本删除Windows 7中许多文件的文件名的某些部分?

使用批处理脚本在目录中获取文件名

在Windows批处理脚本中特殊字符的倍数后截断文件名?

使用cmd批处理查找具有相同文件名的所有文件

使用Windows批处理脚本(保留扩展名)更改文件名?

Windows批处理脚本,并使用“!”处理文件名 For循环中的感叹号

Windows中的批处理文件名和行数

根据批处理脚本中的文件名忽略文件

将文件移动到基于文件名批处理脚本创建的新位置

批处理脚本以删除文件名中具有连续编号的文件,最多可达特定数量