返回列表 发帖

求一个批处理脚本重命名拖拽图片

本帖最后由 gytqqq 于 2020-3-21 20:58 编辑

A为一个空文件夹
我从其他文件夹拖拽图片到A文件夹,使图片命名为0001,再拖拽一张图片命名为0002,以此类推。谢谢给位大佬。麻烦支持的图片格式尽量全一些。

其他文件夹与A文件夹不在同一个盘符,拖拽即复制。

20元酬谢,如果实现起来略复杂可酌情加钱。

win10系统环境

非常感谢wujunkai和Gin_Q二位的帮忙
我会为两位都转账的 谢谢

本帖最后由 Gin_Q 于 2020-3-22 08:53 编辑
@echo off& setlocal enabledelayedexpansion &rem by Gin
::可以检查是否拖入了上一次文件(间隔超过一次无法检测)
::如果中间删掉了一个文件可以自动补充(需要重新打开程序)
::需要把程序放在修改后的图片文件目录
::增加图片格式为原有格式(任意格式文件都可以)
::REV 01
::检查文件名
for /l %%a in (1,1,9999) do (
if %%a lss 10 ( for /f %%b in ('attrib -i "000%%a*"') do (
if "%%b" equ "找不到文件" ( echo 正在处理第%%a个文件
call :input
copy !file! "000%%a!suffix!")))
if %%a geq 10 ( if %%a lss 100 (for /f %%b in ('attrib -i "00%%a*"') do (
if "%%b" equ "找不到文件" ( echo 正在处理第%%a个文件
call :input
copy !file! "00%%a!suffix!"))))
if %%a geq 100 ( if %%a lss 1000 (for /f %%b in ('attrib -i "0%%a*"') do (
if "%%b" equ "找不到文件" ( echo 正在处理第%%a个文件
call :input
copy !file! "0%%a!suffix!"))))
if %%a geq 1000 ( for /f %%b in ('attrib -i "%%a*"') do (
if "%%b" equ "找不到文件" ( echo 正在处理第%%a个文件
call :input
copy !file! "%%a!suffix!")))
)
echo 文件数已到达9999
pause&exit
:input
set /p file=请拖入文件:
if "!file!" equ "!che!" goto :input
for /f "tokens=*" %%a in ("!file!") do set "suffix=%%~xa"
set "che=!file!"
exit /b 0COPY

TOP

@echo off
@setlocal enabledelayedexpansion
set num=1
set name=0001
call:count
:main
    for /R %%i in (*.jpg,*.jpeg,*.png,*gif,*.bmp,*.ico,*.dib,*.jpe) do (
        if not %%~ni LSS %num% (
            rem echo rename "%%i" %name%.%%~xi ----  %num%
            rename "%%i" %name%.%%~xi
            set /A num=num+1
            call:int
            goto:main
        )
    )
    call:sleep 125
goto:main
:count
    rem 计算已重命名的文件数
    if exist %num%.jpg (
        set /A num=num+1
        call:int
        goto:count
    )
goto:eof
:int
    rem 统一格式
    set name=00000%num%
    set name=%name:~-4%
goto:eof
:sleep
    rem 防高频
    echo WScript.sleep %1 > sleep.vbs
    start /wait sleep.vbs
    del sleep.vbs
goto:eofCOPY
支持几乎所有图片后缀名。
支持9999以内。
错了再通知我,我只测试到23.

TOP

<# :
cls
@echo off
rem 有问题,可加QQ956535081及时沟通
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default)))"
pause
exit
#>
$folder='.';
$dic=New-Object 'System.Collections.Generic.Dictionary[string,int]';
for($i=100001;$i -le 199999;$i++){
    $n=$i.toString().Substring(1);
    $dic.Add($n,0);
};
$files=@(dir -liter $folder|?{('.bat' -ne $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
    $base=$files[$i].BaseName;
    if(-not $dic.ContainsKey($base)){
        foreach($it in $dic.Keys){
            if($dic[$it] -eq 0){
                $newname=$it+$files[$i].Extension;
                write-host ($files[$i].Name+' --> '+$newname);
                mv -liter $files[$i].FullName ($files[$i].Directory.FullName+'\'+$newname);
                $dic[$it]++;break;
            };
        };
    }else{$dic[$base]++};
}COPY
提供bat代写
QQ: 956535081

TOP

回复 3# wujunkai


    生成的文件都带点。。。比如0001. 0002. 0003. 能不能把点去掉

TOP

回复 2# Gin_Q


    乱码 看不懂啊

TOP

回复 6# gytqqq


    把脚本另存为ANSI格式

TOP

回复 5# gytqqq


    抱歉,在细节的处理上有点问题,已改正。
@echo off
@setlocal enabledelayedexpansion
set num=1
set name=0001
call:count
:main
    for /R %%i in (*.jpg,*.jpeg,*.png,*gif,*.bmp,*.ico,*.dib,*.jpe) do (
        if not %%~ni LSS %num% (
            rem echo rename "%%i" %name%%%~xi ----  %num%
            rename "%%i" %name%%%~xi
            set /A num=num+1
            call:int
            goto:main
        )
    )
    call:sleep 125
goto:main
:count
    rem 计算已重命名的文件数
    if exist %num%.jpg (
        set /A num=num+1
        call:int
        goto:count
    )
goto:eof
:int
    rem 统一格式
    set name=00000%num%
    set name=%name:~-4%
goto:eof
:sleep
    rem 防高频
    echo WScript.sleep %1 > sleep.vbs
    start /wait sleep.vbs
    del sleep.vbs
goto:eofCOPY
觉得满意的话请付款[滑稽]

TOP

回复 8# wujunkai


    谢谢 暂时测试没有问题 我给您转账 支付宝账号给我

TOP

回复 7# Gin_Q


    谢谢 暂时测试没有问题 我给您转账 支付宝账号给我

TOP

回复 9# gytqqq


    没有支付宝。。。微信可?18906991102

TOP

1358491044@qq.com

TOP

回复 10# gytqqq


    二楼我已经更新了程序,支持任意格式文件!

TOP

回复 12# Gin_Q


    您好 能不能拖拽完文件不用回车啊 直接更名 文件多了有点吃不消了。。。。

TOP

回复 14# gytqqq


    你不转账就算了,何必说有偿求助呢!

TOP

返回列表