:movesub cls echo.&echo.&echo. echo ╭─────────╮ echo ╭────────┤ 預處理子目錄 ├─────────╮ echo │ ╰─────────╯ │ echo │ │ echo │ 如果當前目錄的子目錄中存在照片,而你需要把 │ echo │ │ echo │ 它們都放到父目錄下,并刪除父目錄及其所有子目錄下 │ echo │ │ echo │ 的空文件夾,那么,這個功能將是非常有用的。 │ echo │ │ echo │ 注意:此處的空文件夾是指刪除父目錄及其所有子 │ echo │ │ echo │ 目錄下的Thumbs.db和*.ctg文件后形成的空文件夾,以 │ echo │ │ echo │ 及原本就存在的空文件夾。 │ echo │ │ echo ╰────────────────────────────╯ echo. echo 返回上一步請按 1 退出請按 0 echo ────────────────────────────── echo. set MoveSub= set /p MoveSub= 是否把照片移動到父目錄下并刪除空目錄(是=Y 否=N): if not defined MoveSub goto movesub set "MoveSub=%MoveSub:"=%" if not defined MoveSub goto movesub if "%MoveSub%"=="0" exit if "%MoveSub%"=="1" goto source if /i "%MoveSub%"=="y" ( set num=0 set WhetherMove=M for /f "delims=" %%i in ('dir /ad /b /s "%Source%/" 2^>nul') do ( for /f "delims=" %%j in ('dir /a-d /b /s "%%i/*.jpg" 2^>nul') do ( set route=&set postfix= setlocal enabledelayedexpansion call :re_name "%%j" "%Source%" "%%~nj" move "%%j" "!Destination_1!">nul 2>nul endlocal set /a num+=1 ) title %TT% 正在處理文件:"%%i" ) del /a /f /q /s "%Source%/Thumbs.db">nul 2>nul del /a /f /q /s "%Source%/*.ctg">nul 2>nul for /f "delims=" %%i in ('dir /ad /b /s "%Source%/"^|sort /r') do ( rd /q "%%i" 2>nul&title %TT% 處理文件:"%%i" ) title %TT% 正在處理的目錄:"%Source%" echo.&call echo 共處理了 %%num%% 張照片,按任意鍵繼續... pause>nul ) else if /i not "%MoveSub%"=="n" goto movesub
:whethermove cls echo. echo ╭─────────╮ echo ╭────────┤ 照片處理方式 ├─────────╮ echo │ ╰─────────╯ │ echo │ │ echo │ 如果不想刪除要處理文件夾下的照片,請選擇復 │ echo │ │ echo │ 制功能;如果不保留原有的照片,請選擇移動文件。 │ echo │ │ echo │ 注意:移動文件后,將會刪除父目錄下的所有空文 │ echo │ │ echo │ 件夾。此處的空文件夾是指刪除父目錄及其所有子目錄 │ echo │ │ echo │ 下的Thumbs.db和*.ctg文件后形成的空文件夾,以及原 │ echo │ │ echo │ 本就存在的空文件夾。 │ echo │ │ echo │ 另:同名文件將作重命名處理,具體方式為:在文 │ echo │ │ echo │ 件名后添加 -序號 。比如重命名為 abc-1.jpg │ echo │ │ echo ╰────────────────────────────╯ echo. echo 返回上一步請按 1 退出請按 0 echo ────────────────────────────── echo. set WhetherMove= set /p WhetherMove= 移動文件還是復制文件(移動=M 復制=C): if not defined WhetherMove goto whethermove set "WhetherMove=%WhetherMove:"=%" if "%WhetherMove%"=="0" exit if "%WhetherMove%"=="1" goto movesub set flag= if /i "%WhetherMove%"=="M" set flag=1 if /i "%WhetherMove%"=="C" set flag=1 if not defined flag goto whethermove if /i "%MoveSub%"=="y" goto destination
:whethersub echo. set WhetherSub= set /p WhetherSub= 是否處理子目錄(是=Y 否=N): if not defined WhetherSub goto whethersub set "WhetherSub=%WhetherSub:"=%" if /i "%WhetherSub%"=="0" exit if /i "%WhetherSub%"=="1" goto whethermove if /i "%WhetherSub%"=="y" ( set WhetherSub=/s goto destination ) if /i "%WhetherSub%"=="n" ( set WhetherSub= goto destination ) goto whethersub
:destination echo. title %TT% 程序所在目錄:"%cd%" set Destination= set /p Destination= 請輸入保存路徑(保存在程序所在目錄下請直接回車): if not defined Destination set "Destination=%cd%" set "Destination=%Destination:"=%" if "%Destination%"=="0" exit if "%Destination%"=="1" goto whethermove echo "%Destination%"|find ":">nul 2>nul||set "Destination=%cd%/%Destination%" echo "%Destination%"|find /i "%Source%">nul 2>nul&&( cls for /l %%i in (1,1,7) do echo. echo 為了不重復處理照片,不允許把保存路徑設置到源文件所在目錄下 echo.&echo 請重新設置保存路徑 echo.&echo. goto destination ) md "%Destination%" 2>nul
:wise cls echo.&echo.&echo.&echo.&echo. echo ╭────────╮ echo ╭─────────┤ 選擇整理方式 ├─────────╮ echo │ ╰────────╯ │ echo │ │ echo │ 有兩種整理方式可供選擇: │ echo │ │ echo │ a 按文件尺寸整理 (如800×600) │ echo │ │ echo │ b 按照拍攝日期整理(如2008-01-01) │ echo │ │ echo ╰────────────────────────────╯ echo. echo 返回上一步請按 1 退出請按 0 echo ────────────────────────────── echo. set Wise= set /p Wise= 請選擇(a/b): if not defined Wise goto wise set "Wise=%Wise:"=%" if not defined Wise goto wise if "%Wise%"=="0" exit if "%Wise%"=="1" goto whethermove if /i "%Wise%"=="a" goto folders_dimesion if /i "%Wise%"=="b" goto folders_date goto wise
:folders_dimesion cls for /l %%i in (1,1,10) do echo. echo 正在處理中,請稍候... set num=0 call :dimesion "%Source%" if defined WhetherSub ( for /f "delims=" %%i in ('dir /ad /b /s "%Source%" 2^>nul') do call :dimesion "%%i" ) call :del_blank pause>nul&goto source
:folders_date cls echo.&echo.&echo. echo ╭─────────╮ echo ╭────────┤ 選擇目錄樹格式 ├─────────╮ echo │ ╰─────────╯ │ echo │ │ echo │ 在保存路徑下,將建立以照片拍攝日期為名的文 │ echo │ │ echo │ 件夾,這些文件夾的目錄樹結構如下: │ echo │ │ echo │ a 年-月-日(如 2007-01-01) │ echo │ │ echo │ b 月/日期(如 01/2007-01-01) │ echo │ │ echo │ c 年/日期(如 2007/2007-01-01) │ echo │ │ echo │ d 年/月/日期 (如 2007/01/2007-01-01) │ echo │ │ echo ╰────────────────────────────╯ echo. echo 返回上一步請按 1 退出請按 0 echo ────────────────────────────── echo. set FoldersTree= set /p FoldersTree= 請選擇(a/b/c/d): if not defined FoldersTree goto folders_date set "FoldersTree=%FoldersTree:"=%" if "%FoldersTree%"=="0" exit if "%FoldersTree%"=="1" goto whethermove set choice= for %%i in (a b c) do if /i "%FoldersTree%"=="%%i" set choice=1 if not defined choice goto folders_date cls for /l %%i in (1,1,10) do echo. echo 正在處理中,請稍候... set num=0 for /f "delims=" %%i in ('dir /a-d /b %WhetherSub% "%Source%/*.jpg" 2^>nul') do ( set /a num+=1 jhead -ft "%%i">nul 2>nul if defined WhetherSub ( for /f "delims=" %%j in ("%%i") do ( set str=%%~tj set route=&set postfix= setlocal enabledelayedexpansion set str=!str:~0,10! set Y=!str:~0,4!&set M=!str:~5,2!&set D=!str:~8,2! if /i "%FoldersTree%"=="a" set Y=&set M= if /i "%FoldersTree%"=="b" set Y= if /i "%FoldersTree%"=="c" set M= md "%Destination%/!Y!/!M!/!str!" 2>nul if /i "%WhetherMove%"=="M" ( call :re_name "%Source%/%%i" "%Destination%/!Y!/!M!/!str!" "%%~ni" move "%%j" "!Destination_1!">nul 2>nul ) else ( call :re_name "%Source%/%%i" "%Destination%/!Y!/!M!/!str!" "%%~ni" copy "%%j" "!Destination_1!">nul 2>nul ) title %TT% 正在處理文件:"%%i" endlocal ) ) else ( for /f "delims=" %%j in ("%Source%/%%i") do ( set str=%%~tj set route=&set postfix= setlocal enabledelayedexpansion set str=!str:~0,10! set Y=!str:~0,4!&set M=!str:~5,2!&set D=!str:~8,2! if /i "%FoldersTree%"=="a" set Y=&set M= if /i "%FoldersTree%"=="b" set Y= if /i "%FoldersTree%"=="c" set M= md "%Destination%/!Y!/!M!/!str!" 2>nul if /i "%WhetherMove%"=="M" ( call :re_name "%Source%/%%i" "%Destination%/!Y!/!M!/!str!" "%%~ni" move "%%j" "!Destination_1!">nul 2>nul ) else ( call :re_name "%Source%/%%i" "%Destination%/!Y!/!M!/!str!" "%%~ni" copy "%%j" "!Destination_1!">nul 2>nul ) title %TT% 正在處理文件:"%Source%/%%~nxi" endlocal ) ) ) call :del_blank pause>nul&goto source
:dimesion :: 按照像素值在目的路徑下建立文件夾 for /f "tokens=2,3*" %%i in ('jhead -cs nul "%~1/*.jpg" 2^>nul^|findstr /i "name Resolution" 2^>nul') do ( if "%%j"==":" ( set "Source=%%k"&set "name=%%~nk" title %TT% 正在處理文件:"%%k" ) else ( setlocal enabledelayedexpansion set "dimesion=%%j%%k" set "dimesion=!dimesion:x =×!" set "Destination=%Destination%/!dimesion!" md "!Destination!" 2>nul set route=&set postfix= if /i "%WhetherMove%"=="M" ( call :re_name "!Source!" "!Destination!" "!name!" move "!Source!" "!Destination_1!">nul 2>nul ) else ( call :re_name "!Source!" "!Destination!" "!name!" copy "!Source!" "!Destination_1!">nul 2>nul ) endlocal set /a num+=1 ) ) goto :eof
:re_name if not defined route ( set "route=%~2" set "filename=%~3" ) :re_name_loop if not exist "%route%/%filename%%postfix%.jpg" ( set "Destination_1=%route%/%filename%%postfix%.jpg" set _num=0 goto :eof ) else ( set /a _num+=1 call set "postfix=-%%_num%%" goto re_name_loop ) goto :eof
:del_blank if /i "%WhetherMove%"=="M" ( del /a /f /q /s "%Source%/Thumbs.db">nul 2>nul del /a /f /q /s "%Source%/*.ctg">nul 2>nul for /f "delims=" %%i in ('dir /ad /b /s "%Source%/"^|sort /r') do (rd /q "%%i" 2>nul) rd /q "%Source%" 2>nul ) title %TT% 當前目錄:"%cd%" echo.&echo.&echo 共處理了 %num% 張照片,按任意鍵繼續... goto :eof