感謝點進來看的您
想請問各位前輩手邊有一些資料夾與子資料夾因為整理的因素想要改檔名
找了KenRename等軟體皆無法達到我的需求,想請教各位前輩批次檔有沒有可解決此問題
針對資料夾與子資料夾名稱改名
如: 照片篇/風景
創立時間 照片篇資料夾為107/06/03 風景資料夾為107/09/30
想要的結果為 照片篇資料夾改為 1070603-照片篇
風景資料夾改為 1070930-風景
只有資料夾改檔名裡面的照片影片皆不動...
再一次謝謝點進來看此篇文章的您們~
希望有解!
根據樓主的需求要使用批次檔來處理,那麼我就來寫一個參考一下。
根據我對問題的理解,樓主要把資料夾及子資料夾改名為以資料夾的建立日期來命名,由於樓主沒有交待資料夾結構,那麼我假設如下的資料夾結構︰
D:\我的珍藏照片\照片篇\
奇怪的東西\
可愛的動物\
狗狗\
喵喵\
豬豬\
帥氣的超級跑車\
DIABLO\
BMW\
風景\
溪頭\
日月潭\
阿里山\
奮起湖\
那麼以下批次檔會把「D:\我的珍藏照片\」以下的所有子目錄都以各目錄的建立日期重新命名,例如原本的「D:\我的珍藏照片\照片篇\可愛的動物\狗狗」會改成(舉例)「D:\我的珍藏照片\1070603-照片篇\1070731-可愛的動物\1070801-狗狗」
@ECHO OFF
REM
REM Define variables
REM
SET RT_ENTRY_DIR=D:\我的珍藏照片
SET RT_TMP_DIR=%TMP%
SET RT_TMP_FILE1=%RT_TMP_DIR%\tmp1.txt
SET RT_TMP_FILE2=%RT_TMP_DIR%\tmp2.txt
SET RT_TMP_FILE3=%RT_TMP_DIR%\tmp3.txt
SET RT_TMP_NEW_FILE=%RT_TMP_FILE1%
SET RT_TMP_OLD_FILE=%RT_TMP_FILE2%
SET RT_TMP_ADD_FILE=%RT_TMP_FILE3%
REM
REM Create 3 empty temporary files which are used to store all
REM sub-directory paths under %RT_ENTRY_DIR% and with deepest first.
REM
@ECHO OFF>"%RT_TMP_FILE1%"
@ECHO OFF>"%RT_TMP_FILE2%"
@ECHO OFF>"%RT_TMP_FILE3%"
REM
REM Backup current directory path and enter %RT_ENTRY_DIR% directory.
REM
PUSHD .
CHDIR /D "%RT_ENTRY_DIR%"
REM
REM Use shell built-in command "DIR" to list all directories recursively
REM and reverse the result on the fly.
REM
REM The final file is %RT_TMP_OLD_FILE%
REM
FOR /F "delims=" %%i IN ('DIR /AD /S /B') DO (
ECHO "%%i"> %RT_TMP_NEW_FILE%
COPY /Y /B "%RT_TMP_NEW_FILE%" + "%RT_TMP_OLD_FILE%" "%RT_TMP_ADD_FILE%"> NUL
CALL :SwapOldAdd
)
REM
REM For each directory listed in %RT_TMP_OLD_FILE%, rename it with
REM creation timestamp prefix.
REM
FOR /F "usebackq delims=" %%i IN ("%RT_TMP_OLD_FILE%") DO (
CALL :RenameDir %%i
)
POPD
GOTO End
REM
REM Subroutine to rename directory. The shell command DIR /TC will list
REM the directory with creation time.
REM
:RenameDir
FOR /F "usebackq tokens=1,2,3,4* delims=/ " %%r IN (`DIR /TC %1 ^| FINDSTR /R "^.*[^.]\.$"`) DO (
REM YYYY MM DD
CALL :RenameTWYearDir %%r %%s %%t %1
)
GOTO :EOF
REM
REM Actually rename the directory to Taiwan year.
REM
:RenameTWYearDir
REM Convert to Taiwan(ROC) year.
SET RT_LOC_TWY=%1
IF /I %1 GTR 1911 SET /A RT_LOC_TWY=-1911+%1
REM Begin to rename.
RENAME %4 "%RT_LOC_TWY%%2%3-%~n4%~x4"
GOTO :EOF
REM
REM This subroutine swap the file names of RT_TMP_OLD_FILE and RT_TMP_ADD_FILE
REM
:SwapOldAdd
FOR %%r IN ("%RT_TMP_OLD_FILE%") DO SET RT_LOC_OLD=%%~nr%%~xr
FOR %%r IN ("%RT_TMP_ADD_FILE%") DO SET RT_LOC_ADD=%%~nr%%~xr
RENAME "%RT_TMP_OLD_FILE%" "%RT_LOC_OLD%R"
RENAME "%RT_TMP_ADD_FILE%" "%RT_LOC_OLD%"
RENAME "%RT_TMP_OLD_FILE%R" "%RT_LOC_ADD%"
GOTO :EOF
:End
REM Remove all temporary files.
ERASE "%RT_TMP_FILE1%" "%RT_TMP_FILE2%" "%RT_TMP_FILE3%"
用Python + pathlib應該可以超快處理好