【问题标题】:Batch Scripting moving and renaming files批处理脚本移动和重命名文件
【发布时间】:2014-07-22 20:59:17
【问题描述】:

我还有一个问题,非常相似 Batch Scripting Moving files with timestamp 但我遇到了问题。

我有一个文件系统 C:\Test\Baseline - 在 Baseline 文件夹下,我有许多文件夹,从 1 到 10+,这些都是图像文件。我想将那些仅以 -not tasty.jpg 文件结尾的文件夹中的所有图像复制到基线文件夹中,但删除 -not tasty.jpg 部分。

这里有一个例子:
C:\Test\Baseline:apple.jpg、orange.jpg、watermellow.jpg、strawberry.jpg、eggs.jpg
C:\Test\Baseline\07-14-14:apples-tasty.jpg、苹果不好吃.jpg,水果不好吃.jpg,水果不好吃.jpg
C:\Test\Baseline\07-16-14:cherry-tasty.jpg,樱桃不好吃.jpg,橙子味道.jpg,橙子不好吃.jpg

所以最后当我运行这个批处理脚本时,它应该从 14 年 7 月 14 日 apple-not taste.jpg 和 fruits-not taste.jpg 将它们重命名为不带 -not taste.jpg --> apple。 jpg 和 fruits.jpg 移动/复制到它的父目录 C:\Test\Baseline 并在必要时覆盖 - 也将cherry-not taste.jpg、orange-not taste.jpg -->cherry.jpg、orange.jpg 移动/复制到 @ 987654328@

所以我们剩下
C:\Test\Baseline:apple.jpg、orange.jpg、watermellow.jpg、strawberry.jpg、eggs.jpg、fruits.jpg、cherry.jpg

我希望你能理解这一点。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: batch-file scripting command-prompt


    【解决方案1】:

    希望这对你有用 -

    @echo OFF
    
    cd D:\test\baseline
    
    for /f "delims=" %%i in ('dir /s /b "*-not tasty.*"') do copy /y "%%~fi" d:\test\baseline\* >nul 2>&1
    
    for /f "delims=" %%i in ('dir /b "*-not tasty.*"') do CALL :rename "%%i" 
    goto :EOF
    
    :rename
    set filename=%1
    set newfilename=%filename:-not tasty=%
    ren %filename% %newfilename% >nul 2>&1
    if %errorlevel% EQU 1 del %newfilename% & ren %filename% %newfilename%
    
    :EOF
    

    干杯, G

    【讨论】:

    • 嘿 gbabu,这行得通!但它也会发出此错误消息Could Not Find D:\test\baseline\-not tasty The syntax of the command is Incorrect 但它确实有效。这个/有一个小修复吗?谢谢
    • 啊。忘记在“goto :EOF”之前换行,就在第二个 for 循环之后。现在应该没问题了。
    • 太棒了!有用!谢谢@gbabu!你能帮我解决这个其他问题吗stackoverflow.com/questions/24563087/… 大部分都完成了,但我只需要删除 -tasty 并移动文件....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多