You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求改进音乐文件夹整理批处理脚本:添加图片缩放与无用文件删除功能

请求改进音乐文件夹整理批处理脚本:添加图片缩放与无用文件删除功能

Hey Shane, let's refine your music folder organizing batch script to add those two missing features—image resizing and unwanted file deletion. I'll walk you through the changes and share the full updated script below.

First, a quick recap of your current script's functionality:

  • Restructures folders from Artist - Album format to Artist/Album (moving all files into the subfolder)
  • Renames any JPG in the album folder to Folder.jpg

Now, let's add the new features:

1. Deleting unwanted files (.log, .txt, .info)

This is straightforward with the del command. We'll add a recursive delete command to target all those file types across all your folders.

2. Resizing Folder.jpg to 350x350

Windows doesn't have a built-in command-line image resizer, so we'll use a lightweight, free tool called IrfanView (it's perfect for batch image tasks). Here's how to set it up:

  • Grab the portable or installed version of IrfanView (it’s tiny and free)
  • Note the full path to i_view64.exe (or i_view32.exe for 32-bit systems)
  • We’ll add a command to call IrfanView’s batch resize right after renaming the JPG to Folder.jpg

Full Updated Batch Script

@echo off
cd /d "%~dp0"
setlocal enabledelayedexpansion

:: Step 1: Delete unwanted files (.log, .txt, .info) recursively
echo Deleting unwanted files...
del /s /q *.log *.txt *.info >nul 2>&1

:: Step 2: Restructure folders from "Artist - Album" to "Artist/Album"
echo Restructuring folders...
for /f delims^= %%i in ('dir /a:-a /b "* - *"') do (
    for /f "usebackq tokens=1* delims=- " %%G in ('echo "%%~nxi"') do (
        set "artist=%%~G"
        set "album=%%~H"
        :: Trim trailing space from artist name
        set "artist=!artist:~0,-1!"
        :: Trim leading space from album name
        set "album=!album:~1!"
        :: Rename the album folder
        ren "%%~i" "!album!"
        :: Create artist folder if it doesn't exist
        if not exist "!artist!" mkdir "!artist!"
        :: Move album folder into artist folder
        move "!album!" "!artist!"
    )
)

:: Step 3: Rename JPGs to Folder.jpg and resize to 350x350
echo Processing album art...
:: Replace this path with your actual IrfanView executable path
set "irfanview_path=C:\PortableApps\IrfanView\i_view64.exe"

for /r /d %%i in (*) do (
    if exist "%%~fi\*.jpg" (
        :: Rename the first JPG found to Folder.jpg
        for /f tokens^=* %%I in ('%__APPDIR__%where.exe "%%~i:*.jpg"') do (
            ren "%%~fI" "Folder.jpg"
            :: Resize Folder.jpg to 350x350 (maintains aspect ratio, pads if needed)
            "!irfanview_path!" "%%~fi\Folder.jpg" /resize=(350,350) /aspectratio /saveas="%%~fi\Folder.jpg" /quiet
            goto :next_jpg
        )
        :next_jpg
    )
)

echo Done!
endlocal
pause

Key Notes:

  • IrfanView Path: Make sure to update the irfanview_path variable to match where you saved IrfanView's executable. If you prefer ImageMagick instead, replace the IrfanView line with:
    convert "%%~fi\Folder.jpg" -resize 350x350^> -gravity center -extent 350x350 "%%~fi\Folder.jpg"
    
  • Folder Restructuring: I cleaned up the original loop logic to use setlocal enabledelayedexpansion for cleaner variable handling (no more messy call labels).
  • Quiet Operations: The /quiet flag in IrfanView keeps it running in the background without popping up windows.
  • Unwanted Files: The del /s /q command deletes files silently across all subfolders.

If you run into any snags with paths or tool setup, just let me know—I can help tweak it further!

备注:内容来源于stack exchange,提问作者Shane Cusack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 08:13:09