返回列表 发帖

[已解决]20元求多文件夹下的指定同名文件问题

已有多个文件情况如下:
D:\fcnlast\picture\train\ADE_train_00000001_json\
D:\fcnlast\picture\train\ADE_train_00000002_json\
D:\fcnlast\picture\train\ADE_train_00000003_json\
D:\fcnlast\picture\train\ADE_train_00000004_json\
D:\fcnlast\picture\train\ADE_train_00000005_json\
等等140个文件
每个文件夹里面有五个文件:img.png;info.yaml;label.png;label_names.txt;label_viz.png五个同名文件
把每个文件夹里面的label.png这一个复制粘贴重命名如下:
D:\fcnlast\picture\traincopy\ADE_train_00000001_json.png
D:\fcnlast\picture\traincopy\ADE_train_00000002_json.png
D:\fcnlast\picture\traincopy\ADE_train_00000003_json.png
简而言之就是多文件夹下的指定同名文件用上一级文件名命名并存放在同一文件夹下,一开始没有描述清楚,重新编辑,增加悬赏,非常感谢!
微信支付宝都可以,多谢!!!

@echo off
if not exist "D:\fcnlast\picture\traincopy" (
    md "D:\fcnlast\picture\traincopy"
)
for /f "delims=" %%i in ('dir /b /s /a-d "D:\fcnlast\picture\train\*.png"') do (
    for /f %%j in ("%%i\..") do (
        copy "%%i" "D:\fcnlast\picture\traincopy\%%~nxj%%~xi"
    )
)COPY
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本帖最后由 zaqmlp 于 2019-5-9 15:51 编辑
@echo off
set info=互助互利,支付宝扫码头像,感谢赞助
rem 有问题,可加QQ956535081及时沟通
title %info%
cd /d "%~dp0"
set "原文件夹=D:\fcnlast\picture\train"
set "新文件夹=D:\fcnlast\picture\traincopy"
if not exist "%新文件夹%" md "%新文件夹%"
powershell -NoProfile -ExecutionPolicy bypass ^
    dir -liter '%原文件夹%' -r^|?{($_ -is [System.IO.FileInfo]) -and ($_.Name -eq 'label.png')}^|group {$_.Name}^|%%{^
        if($_.count -ge 2){^
            foreach($it in $_.Group){^
                $newname=$it.Directory.Name+$it.Extension;^
                write-host ($it.FullName+' --^> %新文件夹%\'+$newname);^
                cp -liter $it.FullName ('%新文件夹%\'+$newname) -force;^
            };^
        };^
    };^
    write-host '%info%' -ForegroundColor green;
pauseCOPY
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 2# Batcher


    您好!我一开始描述的有点问题导致处理结果不理想,可否再帮我看一下,已增加悬赏,十分感谢!!!

TOP

回复 3# zaqmlp


      您好!我一开始描述的有点问题导致处理结果不理想,可否再帮我看一下,已增加悬赏,十分感谢!!!

TOP

回复 5# 学习小白


只是复制重命名这个label.png吗?加我QQ
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 6# zaqmlp


    是的只是label.png这一个文件,已经好友,是叫zouni吗??

TOP

回复 7# 学习小白
已修改
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 4# 学习小白
@echo off
if not exist "D:\fcnlast\picture\traincopy" (
    md "D:\fcnlast\picture\traincopy"
)
for /f "delims=" %%i in ('dir /b /s /a-d "D:\fcnlast\picture\train\*.png"') do (
    if "%%~nxi" equ "label.png" (
        for /f %%j in ("%%i\..") do (
            copy "%%i" "D:\fcnlast\picture\traincopy\%%~nxj%%~xi"
        )
    )
)COPY
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表