批处理文件以检查具有相同名称的文件 [英] Batch file to check files with same name

查看:56
本文介绍了批处理文件以检查具有相同名称的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中每个存档文件都有一个具有相同名称的对应图像文件.如果按文件名排序,则文件夹的结构为:

I've a folder where every archive file has a correspondant image file with the same name. If ordered by file name then the structure of the folder is:

  • 文件夹
    • File1.zip
    • File1.jpg
    • File2.zip
    • File2.jpg
    • File3.zip (此文件应移至子文件夹)
    • File4.zip
    • File4.jpg

    如果存档文件没有其图像文件,则应将其移动到另一个文件夹.

    If the archive file has not its image file then it should be moved to another folder.

    一个问题是,并非所有存档文件都是.zip,而且不是.rar或7z,也不是所有图像都是.jpg也是.jpeg或.png

    One problem is that not all archive files are .zip, but also .rar or 7z and not all images are .jpg but also .jpeg or .png

    如果您能向我指出解决方案,那就太好了,因为我是一名网页设计师,而.bat文件并不是我的专长:)

    It would be great if you could point me to the solution because I'm a web designer and .bat files are not really my domain :)

    推荐答案

    虽然[SO]不是脚本编写服务,但我确实发现任务很重要.
    在下一批中将第2 + 3行中的路径调整为适合您的环境.

    While [SO] isn't a script writing service, I did find the task interessent.
    Adapt the pathes in line 2+3 in the following batch to your environment.

    @Echo off&SetLocal 
    PushD "X:\folder\to\check"
    Set "MoveToFolder=Y:\move\arc\to"
    For /f "delims=" %%Z in ('Dir /B *.zip *.rar *.7z') Do (
      Set "FoundPic="
      For /f "delims=" %%P in (
        'Dir /B "%%~nZ*" ^| findstr /i "\.jpg$ \.jpeg$ \.png$" '
      ) Do Set FoundPic=yes
      If not defined FoundPic echo Move "%%Z" "%MoveToFolder%"
    )
    PopD
    

    这篇关于批处理文件以检查具有相同名称的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆