标题: [文件操作] [分享]批处理按日期整理文件 [打印本页]
作者: batman 时间: 2010-11-25 10:30 标题: [分享]批处理按日期整理文件
本批可将当前文件夹下所有文件(不含文件夹)分年分月分日(建立年、月、日三级文件夹)复制到名为tmp的文件
夹中,遇有同年同月同日文件名重复的情况(只考虑了10次重复,实际次数可以修改)则按* *-1 *-2 *-3的形式处理:- @echo off&setlocal enabledelayedexpansion
- if exist tmp rd /s /q tmp
- md tmp
- for /f "delims=" %%a in ('dir /a-d /b /s') do (
- set "str=%%~ta"&set "year=!str:~,4!"&set "month=!str:~5,2!"&set "day=!str:~8,2!"
- if not exist tmp\!year!\!month!\!day! md tmp\!year!\!month!\!day!
- set "str=%%~na"
- for /l %%b in (1,1,10) do (
- if exist "tmp\!year!\!month!\!day!\!str!%%~xa" (
- if %%b neq 1 set "str=!str:~,-2!"
- set "str=!str!-%%b"
- )
- )
- copy /y "%%a" "tmp\!year!\!month!\!day!\!str!%%~xa"
- )
- start tmp
复制代码
[ 本帖最后由 batman 于 2010-11-25 10:34 编辑 ]
作者: canyuexiaolang 时间: 2010-11-25 15:44
额,谢谢楼主了。我继续完善我的某某没人回贴的代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |