标题: [原创]文件分类
[打印本页]
作者: SpikeKnox
时间: 2007-2-9 07:14
标题: [原创]文件分类
自己老是下一堆书,分类是样累人的活,我很懒的<img src="images/smilies/face-smile-big.png" align="absmiddle" border="0">
功能:根据设定的关键字用grep过滤,把匹配的文件放到各自的目录中.
@Echo OFF
::
:: BatName: Categorize.bat
:: Version: 0.1
:: Purpose: categorize for files
::
:: Usage: Categorize folderName
:: folderName target folder
::
::
:: grep.exe
::
:: Code by SpikeKnox 2007.02.08
::
SetLocal EnableDelayedExpansion
rem Show help
If == (Type "%~f0" | findstr "^::" && Goto :EOF)
If == (Type "%~f0" | findstr "^::" && Goto :EOF)
rem === ============================================================================
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
Echo.
For %%I IN (%category%) DO (
Echo +
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
Del content.txt
Popd
Echo.
Pause
作者: anqing
时间: 2007-2-9 07:21
一看长的p,就晕
所以,佩服能写的人
作者: SpikeKnox
时间: 2007-2-9 09:13
标题: 呵呵~谢谢捧场!
也不是很长啦。
关键代码就这么多:
For %%I IN (%category%) DO (
Echo +
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.
)
如果不用grep的话,可以用 findstr 命令来替代,不过正则的功能就没那么强了<img src="images/smilies/face-wink.png" align="absmiddle" border="0">
Last edited by SpikeKnox on 2007-2-8 at 08:18 PM ]
作者: redtek
时间: 2007-2-9 11:11
顶~~~欣赏+收藏~~~
作者: lovebaby001
时间: 2010-9-3 17:23
根据设定的关键字用grep过滤,请问grep是什么工具啊?