[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [分享]批处理按日期整理文件

本批可将当前文件夹下所有文件(不含文件夹)分年分月分日(建立年、月、日三级文件夹)复制到名为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 编辑 ]
***共同提高***

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

TOP

返回列表