用脚本实现对文件夹内照片采用拍摄时间及流水号命名

还是之前的老问题,各种来源的照片命名格式不统一,市面上的批量改名软件都比较卡顿。

这次让chatgpt来帮忙写代码:

on run {input, parameters}

  set theFolder to choose folder with prompt "请选择一个文件夹"

  tell application "Finder"
    set theFiles to files of theFolder as alias list
    repeat with i from 1 to the count of theFiles
      set thisFile to item i of theFiles
      set theInfo to the information of thisFile
      try
        set theDate to the creation date of thisFile
      on error
        set theDate to modification date of thisFile
      end try
      set theYear to year of theDate as string
      set theMonth to text -2 thru -1 of (100 + (month of theDate as integer)) as string
      set theDay to text -2 thru -1 of (100 + (day of theDate as integer)) as string
      set theHour to text -2 thru -1 of (100 + (hours of theDate as integer)) as string
      set theMinute to text -2 thru -1 of (100 + (minutes of theDate as integer)) as string
      set theSecond to text -2 thru -1 of (100 + (seconds of theDate as integer)) as string
      set theName to theYear & theMonth & theDay & "_" & theHour & theMinute & theSecond & "_" & i as string
      set name of thisFile to theName & "." & name extension of thisFile
    end repeat
  end tell

  return input
end run

再来一个windows版本。

@echo off
setlocal enabledelayedexpansion

set "srcfolder=%cd%"

set /p "srcfolder=请输入文件夹的完整路径:"

pushd %srcfolder%

set "counter=0"
for /f "tokens=*" %%i in ('dir /b /a-d') do (
  set "filename=%%i"
  for /f "tokens=1-6 delims=.: " %%j in ('dir /tc "!filename!"^|findstr /r /c:"[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]\ [0-9][0-9]"') do (
    set "counter=!counter!+1"
    set "newfilename=%%k_%%l_!counter!%%~xi"
    echo Renaming "!filename!" to "!newfilename!"
    ren "!filename!" "!newfilename!"
  )
)

popd

最后,尝试一下用php实现。

很完美。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Evaporator Core

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值