음악 폴더의 JPEG 크기를 350x350으로 조정하고 불필요한 파일을 삭제하는 일괄 스크립트

음악 폴더의 JPEG 크기를 350x350으로 조정하고 불필요한 파일을 삭제하는 일괄 스크립트

나는 현재 예를 들어 음악 폴더의 이름을 바꾸는 스크립트를 사용하고 있습니다. 모든 파일이 이동된 하위 폴더가 있는 Taylor Swift - 1989새 폴더로 이동합니다 .Taylor Swift1989

.jpg또한 이름을 바꿀 파일을 변경 하기 위해 이름 바꾸기 줄을 추가했습니다 Folder.

.jpg이전 Microsoft Office 2010 그림 프로그램을 통해 작업하는 대신 해당 파일의 크기를 350x350의 더 작은 크기로 조정/확장할 수 있는지 알고 싶습니다 .

마지막으로 원치 않는 파일을 삭제하는 방법을 알 수 없습니다. 이러한 파일은 .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

나에게는 이것이 효과가 있으며, 그것이 당신의 의도대로 되기를 바랍니다. 모든 명령이 수행하는 작업(또는 대부분)을 설명하기 위해 배치 코드에 주석을 채웠습니다. 예상대로 작동하는지 확인하려면 복사본에서만 테스트하세요. 크기 조정 및 Folder.jpg 이름 변경 옵션이 작동하려면 Image Magick이 설치되어 있어야 합니다.

@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

관련 정보