文件夹里文件以日期重命名_将文件重命名为文件日期

文件夹里文件以日期重命名

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the image file is called IMG_0777.jpg, this utility will rename the file to 20081121_134000.jpg.  Works with multiple files, and will recurse sub-directories with the /s option.

此Windows批处理文件对于组织来自数码相机或其他来源的图像文件很有用,但可以有许多其他用途。 它只是重命名文件以匹配其创建日期。 例如,如果您今天在下午1:40拍照,并且图像文件名为IMG_0777.jpg,则此实用程序会将文件重命名为20081121_134000.jpg。 适用于多个文件,并使用/ s选项递归子目录。

Cut-n-paste the following into notepad and save it as a .BAT file:

将以下内容剪切-n-粘贴到记事本中,并将其另存为.BAT文件:

@echo off
 setlocal enabledelayedexpansion
 
 set filespec=%*
 if "%filespec%"=="" goto :help
 
 for /f "delims=" %%F in ('dir/a-d/b/od %filespec%') do (
   set fn=%%~tF
 
   set/a hour=0x!fn:~11,2!
   if !hour! GTR 10 set/a hour=(!hour!-6^) %% 12
   if "!fn:~17,2!"=="PM" set/a hour+=12
   if !hour! LSS 10 set hour=0!hour!
 
   set root=%%~dpF
   set ext=%%~xF
   set nxt=00
   set fn=!fn:~6,4!!fn:~0,2!!fn:~3,2!_!hour!!fn:~14,2!
 
   if exist "!root!!fn!!nxt!!ext!" for /L %%I in (59,-1,1) do (
     set dup=0%%I
     if not exist "!root!!fn!!dup:~-2!!ext!" set nxt=!dup:~-2!
   )
 
   @echo ren "%%F" "!fn!!nxt!!ext!"
         ren "%%F" "!fn!!nxt!!ext!"
 )
 
 dir !root!*!ext! | find/v "Volume"
 
 goto :end
 
:help
 
@echo.
@echo  Renames files to the date and time the file was created, 
@echo  preserving the file extention:  YYYYMMDD_HHMMSS.ext
@echo  Synatx:  %0 filespec [/s]
@echo  A filespec (such as *.jpg) must be specified.
@echo  /s will recurse sub-folders and rename files matching the filespec.
@echo  Example:  %0  E:\DCIM\*.jpg  /s
 
:end
 endlocal

翻译自: https://www.experts-exchange.com/articles/268/Rename-files-to-the-file-date.html

文件夹里文件以日期重命名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值