檔名 自動分類資料夾

各位大能 , 最近偶然間需要分類以檔名為基礎的分類 , 上網找到某位大能寫的.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
2023-07-05 8:39 發佈
文章關鍵字 自動分類資料夾
最快的方法
Everything 直接搜硬碟目錄 CTRL+B 全字 精準搜索 副檔名
.JPG 之類的 全部列表 按照你想丟的文件夾去丟 這樣最快

自動化BAT 還是會有遺漏
TGmax
TGmax 樓主

[汗]小弟愚昧。。。不會用。。。

2023-07-07 9:42
會不會你把 .dat 改成 .bat 就能run了?
TGmax
TGmax 樓主

[笑到噴淚]不小心打錯了啦。。。

2023-07-07 9:41
1tac

不確定你說的抬頭是指什麼. 這個batch檔只要把md "%%~ni"跟move "%%~i" "%%~ni"中間的&&拿掉並分成兩行, 執行後就會把主檔名一樣的檔案都移到同一目錄下

2023-07-07 12:41
TGmax
TGmax 樓主

上面方法測試好像也是一樣,我的需求是例如,我的檔名是:一泊二食-1,一泊二食-2,一泊二食-3,一泊二食-4....... 我想要依檔名一泊二食建立資料夾,然後全部在同一個資料夾裡面,是否可行

2023-07-07 16:58
以下內容存成 organize.bat, 跟要處理的檔案放在同一目錄, 執行即可

@echo off
for %%i in (*) do (
if not "%%~nxi" == "organize.bat" (
for /f "tokens=1-3* delims=-." %%a in ("%%~i") do (
mkdir "%%a"
move "%%~i" "%%a"
)
)
)
TGmax
TGmax 樓主

謝謝大大的分享,這個確定可以!真的很感謝~

2023-07-10 8:14
這下糟糕了
我把這個bat檔丟到我的1.6TB的電影資料夾內

代碼如下

@echo off
for %%i in (*) do (
if not "%%~ni" == "Organizer. bat" (
md "%%~ni" && move "%%~i" "%%~ni" && ren "%%~ni\%%~i" "game.iso"
)
)
暫停

結果全都變成資料夾然後裡面一個映像檔
請問有沒有辦法可以還原


在線等待程序大神解救
感激不盡 (合十)
REM List file names, sorted by file name---------
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
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?