批处理脚本将音乐文件夹中的 JPEG 大小重新调整为 350x350 并删除不需要的文件

批处理脚本将音乐文件夹中的 JPEG 大小重新调整为 350x350 并删除不需要的文件

我目前使用脚本将音乐文件夹重命名为Taylor Swift - 1989一个新文件夹,Taylor Swift其中包含一个子文件夹1989,所有文件都移入其中。

我还添加了一个重命名行来更改.jpg要重命名的文件Folder,效果很好。

我想知道是否可以将该.jpg文件调整大小/缩放到 350x350 的较小尺寸,而不是通过旧的 Microsoft Office 2010 图片程序来执行此操作。

最后,我不知道如何删除不需要的文件,这些文件是.log,,.txt.info

如果我可以在同一个批处理脚本中获得所有这些,那就太棒了。

这是我目前使用的:

@echo off & cd /d "%~dp0"

for /f delims^= %%i in =;(' dir /a:-a /b "* - *"
    ');= do for /f usebackq^tokens^=1*delims^=-^" %%G in =;(`
         set /p "'=%%~nxi"^<nul `);= do call %:^) "%%~G" "%%~H" "%%~dpnxi"

for /r /d %%i in (*)do if exist "%%~fi\*.jpg" for /f tokens^=* %%I in (
'%__APPDIR__%where.exe "%%~i:*.jpg"')do ren "%%~fI" "Folder.jpg"

%:^)
if not "%~1" == "" =;(
     set "_dir=%~1" & set "_sub=%~2"
     call rename "%~3" "%%_sub:~1%%"
     call mkdir "%cd%\%%_dir:~0,-1%%"
     call move "%%_sub:~1%%" "%%_dir:~0,-1%%" 
     );= & exit /b 

答案1

对我来说,这是可行的,我希望它符合您的预期。我在批处理代码中填入了注释,以解释每个命令(或大多数命令)的作用。仅在副本上测试它,以查看它是否按预期工作。您必须安装 Image magick 才能使用调整大小和重命名为 Folder.jpg 选项。

@echo off

:: set here the rootfolder where the music folders are:
set RootFolder=%userprofile%\desktop\music

for /f "delims=" %%a in ('dir /ad /b "%RootFolder%\*-*"') do for /f "tokens=1* delims=-" %%b in ("%%~a") do (
                                                                                                         set "OriginalName=%%~a"
                                                                                                         set "FolderPart1=%%~b"
                                                                                                         set "FolderPart2=%%~c"
                                                                                                         call :Edit "%%~b" "%%~c"
                                                                                                        )
echo This is the end....
exit


:Edit
:: checks and removes if there are white spaces in front and back of new folder names:
if "%FolderPart1:~-1%"==" " (set "FolderPart1=%FolderPart1:~0,-1%" & goto :Edit)
if "%FolderPart2:~0,1%"==" " (set "FolderPart2=%FolderPart2:~1%" & goto :Edit)

:: deletes log txt and info files:
del /q "%RootFolder%\%OriginalName%\*.log"
del /q "%RootFolder%\%OriginalName%\*.txt"
del /q "%RootFolder%\%OriginalName%\*.info"

:: uses image magick to create a resized copy named Folder.jpg of a jpg file inside the original folder: 
magick "%RootFolder%\%OriginalName%\*.jpg" -resize 350x350 "%RootFolder%\%OriginalName%\Folder.jpg"

:: deletes all jpg files except Folder.jpg inside the original folder:
for /f "delims=" %%a in ('dir /b "%RootFolder%\%OriginalName%\*.jpg" ^|find /i /v "Folder.jpg"') do del /q "%RootFolder%\%OriginalName%\%%~a"

:: Creates a new folder from the part before the hifen "-" in the original folder:
if not exist "%RootFolder%\%FolderPart1%" md "%RootFolder%\%FolderPart1%"

:: moves and renames the original folder to the second part or the original foldername (behind the hifen):
move "%RootFolder%\%OriginalName%" "%RootFolder%\%FolderPart1%\%FolderPart2%"
goto :EOF

相关内容