Board logo

标题: [文件操作] [分享]批处理按日期整理文件 [打印本页]

作者: batman    时间: 2010-11-25 10:30     标题: [分享]批处理按日期整理文件

本批可将当前文件夹下所有文件(不含文件夹)分年分月分日(建立年、月、日三级文件夹)复制到名为tmp的文件
夹中,遇有同年同月同日文件名重复的情况(只考虑了10次重复,实际次数可以修改)则按* *-1 *-2 *-3的形式处理:
  1. @echo off&setlocal enabledelayedexpansion
  2. if exist tmp rd /s /q tmp
  3. md tmp
  4. for /f "delims=" %%a in ('dir /a-d /b /s') do (
  5.     set "str=%%~ta"&set "year=!str:~,4!"&set "month=!str:~5,2!"&set "day=!str:~8,2!"
  6.     if not exist tmp\!year!\!month!\!day! md tmp\!year!\!month!\!day!
  7.     set "str=%%~na"
  8.     for /l %%b in (1,1,10) do (
  9.         if exist "tmp\!year!\!month!\!day!\!str!%%~xa" (
  10.            if %%b neq 1 set "str=!str:~,-2!"
  11.            set "str=!str!-%%b"
  12.         )
  13.     )
  14.     copy /y "%%a" "tmp\!year!\!month!\!day!\!str!%%~xa"
  15. )
  16. start tmp
复制代码

[ 本帖最后由 batman 于 2010-11-25 10:34 编辑 ]
作者: canyuexiaolang    时间: 2010-11-25 15:44

额,谢谢楼主了。我继续完善我的某某没人回贴的代码




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2