CODE: [Copy to clipboard]
@Echo OFF
::
:: BatName: Categorize.bat
:: Version: 0.1
:: Purpose: categorize for files
::
:: Usage: Categorize folderName
:: folderName target folder
::
:: [DependOn]
:: grep.exe
::
:: Code by SpikeKnox 2007.02.08
::
SetLocal EnableDelayedExpansion
rem Show help
If [%1]==[/?] (Type "%~f0" | findstr "^::" && Goto :EOF)
If [%1]==[] (Type "%~f0" | findstr "^::" && Goto :EOF)
rem === [Config] ============================================================================
rem 设置类别
Set "category=csharp;sql;script;windows;unix;design"
rem 设置每个类别的关键字(传给grep用的)
Set "csharp=c\W\?sharp\|c#"
Set "sql=sql"
Set "script=script\|perl\|python"
Set "windows=windows\|office\|excel\|word"
Set "unix=unix\|linux"
Set "design=design\|设计"
rem =========================================================================================
rem Goto target folder
Pushd %1 || Pushd %~dp1
rem Build file list
Dir /b /a-d > content.txt
Echo.
Echo [ Categorize ]
Echo.
For %%I IN (%category%) DO (
Echo +[%%I]
Echo.
For /F "delims=*" %%i IN ('grep -i "!%%I!" content.txt') DO (
If NOT EXIST %%I md %%I
IF EXIST %%i ( Echo %%i & Move /y "%%i" %%I\ >NUL 2>NUL )
)
Echo.
)
rem [Clean]
Del content.txt
Popd
Echo.
Pause