各位大能 , 最近偶然間需要分類以檔名為基礎的分類 , 上網找到某位大能寫的.bat , 可是好像有錯導致不能使用 , 是否有哪位大能可以重新編寫一下 , 感謝
來源網址
REM 列出檔案名稱,依照檔名排序---------
dir /b /on > list.txt
REM 找出JPG 檔案
findstr ".JPG" list.txt > target.txt
rem 刪除副檔名-------------------------
@echo off & setlocal enabledelayedexpansion
rem 讀取target.txt所有內容
for /f "eol=* tokens=*" %%i in (target.txt) do (
rem 設定變數a為每行內容
set a=%%i
rem 如果該行有.JPG,則將其改為
set "a=!a:.JPG=!"
rem 把修改後的全部行存入$
echo !a!>>$)
rem 用$的內容替換原來a.txt內容
move $ target.txt
REM 建立資料夾-----------------------------
rem 讀取target.txt所有內容
for /f "eol=* tokens=*" %%i in (target.txt) do (
set string=%%i
echo "%%i"
for /f "tokens=1,2 delims=_" %%a in ("%%i") do (
set BEFORE_UNDERSCORE=%%a
set AFTER_UNDERSCORE=%%b
echo %%a
md %%a
rem 移動檔案到資料夾
move %%i*.* %%a
))
del list.txt
del target.txt
dir /b /on > list.txt
REM Find JPG files
findstr ".jpg" list.txt > target.txt
rem delete file extension-------------------------
@echo off & setlocal enabledelayedexpansion
rem reads all the contents of target.txt
for /f "eol=* tokens=*" %%i in (target.txt) do (
rem sets variable a to the content of each line
set a=%%i
rem If the line has .JPG, change it to
set "a=!a:.JPG=!"
rem saves all modified lines into $
echo !a!>>$)
rem replaces the original a.txt content with the content of $
move $ target.txt
REM Create folder-----------------------------
rem reads all the contents of target.txt
for /f "eol=* tokens=*" %%i in (target.txt) do (
set string=%%i
echo "%%i"
for /f "tokens=1,2 delims=_" %%a in ("%%i") do (
set BEFORE_UNDERSCORE=%%a
set AFTER_UNDERSCORE=%%b
echo %%a
md %%a
rem Move files to folder
move %%i*.* %%a
))
del list.txt
del target.txt
內文搜尋

X