标题: [日期时间] 批处理如何获取视频文件的“创建媒体日期”并重命名给该视频文件? [打印本页]
作者: bdk3521 时间: 2023-4-5 17:29 标题: 批处理如何获取视频文件的“创建媒体日期”并重命名给该视频文件?
问一下,如何获取视频文件的“创建媒体日期”并重命名给该视频文件?
作者: jyswjjgdwtdtj 时间: 2023-4-5 17:51
网上搜了一篇帖子https://www.cnblogs.com/ryanzheng/p/11117469.html
通过wmic获取
作者: bdk3521 时间: 2023-4-5 18:16
本帖最后由 bdk3521 于 2023-4-5 18:33 编辑
网上搜了一篇帖子
通过wmic获取
jyswjjgdwtdtj 发表于 2023-4-5 17:51
测试了,可以把我想要的日期搞出来,参数还没有找到
作者: czjt1234 时间: 2023-4-5 18:58
本帖最后由 czjt1234 于 2023-4-5 19:00 编辑
vbs- s = "D:\aaa" '指定一个文件夹
-
- Set oWshShell = CreateObject("WScript.Shell")
- oWshShell.CurrentDirectory = s
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oShell = CreateObject("Shell.Application")
- Set oFolder = oShell.NameSpace(s)
- Set oFolderItems = oFolder.Items()
- oFolderItems.Filter &H40 + &H80 + &H10000, "*.*"
- For i = 0 To 500
- If oFolder.GetDetailsOf(Null, i) = "创建媒体日期" Then n = i
- Next
- For Each i In oFolderItems
- s = oFolder.GetDetailsOf(i, n)
- If s <> "" Then
- s = RePlace(s, ChrW(8206), "")
- s = RePlace(s, ChrW(8207), "")
- s = "-" & F_D_T(s, "yyyymmdd") & "."
- i.Name = oFSO.GetBaseName(i.Name) & s & oFSO.GetExtensionName(i.Name)
- End If
- Next
- MsgBox "ok"
-
- Function F_D_T(ByVal d, ByVal s)
- Dim oSWbemDateTime, oWMI, i, TimeZone
- Select Case UCase(s)
- Case "CIM_DATETIME"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.Value
- Case "INTERVAL FORMAT"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- oSWbemDateTime.IsInterval = True
- F_D_T = oSWbemDateTime.Value
- Case "FILENAME" 'UTC时间
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.GetFileTime(False)
- Case "UNIX" '10位Unix时间戳,UTC时间
- Set oWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- For Each i In oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
- TimeZone = i.CurrentTimeZone
- Next
- i = DateDiff("s", #1970-01-01 00:00:00#, d)
- F_D_T = i - TimeZone * 60
- Case Else
- s = Replace(s, "yyyy", Year(d), 1, -1, vbTextCompare)
- s = Replace(s, "yy", Right(Year(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "mm", Right("0" & Month(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "m", Month(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "dd", Right("0" & Day(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "d", Day(d), 1, -1, vbTextCompare)
- s = Replace(s, "HH", Right("0" & Hour(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "H", Hour(d), 1, -1, vbTextCompare)
- s = Replace(s, "MM", Right("0" & Minute(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "M", Minute(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "SS", Right("0" & Second(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "S", Second(d), 1, -1, vbTextCompare)
- F_D_T = s
- End Select
- End Function
复制代码
作者: terse 时间: 2023-4-5 19:33
bat- @echo off&setlocal enabledelayedexpansion
- for /f "tokens=1-3*" %%a in ('dir /tc /a-d^|findstr /il "\/"') do echo "%%d" %%a %%b
- pause
复制代码
wmic- @echo off&setlocal enabledelayedexpansion
- for %%i in (*) do (
- set fils=%%~fi
- set fils=!fils:\=\\!
- for /f "skip=1 tokens=1,3,5 delims=. " %%a in ('wmic datafile where name^="!fils!" get CreationDate^|findstr .') do (
- set a=%%a
- echo %%i !a:~0,4!-!a:~4,2!-!a:~6,2!:!a:~8,2!:!a:~10,2!:!a:~12,2!
- )
- )
复制代码
作者: buyiyang 时间: 2023-4-5 20:10
powershell- powershell -c "Get-ChildItem -Filter *.mov | %%{ren $_.FullName ($_.CreationTime.ToString('yyyyMMdd') + $_.Extension)}"
复制代码
作者: bdk3521 时间: 2023-4-5 20:13
batwmic
terse 发表于 2023-4-5 19:33
这个不对,不是媒体创建日期,这个是文件创建日期。
作者: jyswjjgdwtdtj 时间: 2023-4-5 21:20
回复 4# czjt1234
哇 兄台 这是什么用法啊- For i = 0 To 500
- If oFolder.GetDetailsOf(Null, i) = "创建媒体日期" Then n = i
- Next
复制代码
作者: bdk3521 时间: 2023-4-5 21:25
回复 czjt1234
哇 兄台 这是什么用法啊
jyswjjgdwtdtj 发表于 2023-4-5 21:20
跟楼上大神讨论了一晚上了,基本实现功能了,正在解决重命名的问题
作者: buyiyang 时间: 2023-4-5 21:27
回复 8# jyswjjgdwtdtj
应该是在找“创建媒体日期”的索引
作者: buyiyang 时间: 2023-4-5 21:33
第三方命令行工具MediaInfo应该可以
作者: czjt1234 时间: 2023-4-5 21:40
回复 8# jyswjjgdwtdtj
vbs中文手册0.3里面有
作者: Batcher 时间: 2023-10-28 13:16
单个文件-获取.bat- @echo off
- REM 1、下载 MediaInfo 这个命令行工具
- REM https://mediaarea.net/download/binary/mediainfo/23.10/MediaInfo_CLI_23.10_Windows_x64.zip
- REM 2、解压缩之后找到MediaInfo.exe、LIBCURL.DLL放在其中一个目录下:
- REM (1)跟 .bat 脚本放在同一个目录下
- REM (2)放在 C:\Windows\System32 目录下
-
- cd /d "%~dp0"
- for /f %%i in ('mediainfo.exe "input.mp4" ^| findstr /b "Encoded date"') do (
- set "VideoEncodeDate=%%i"
- )
- echo,%VideoEncodeDate%
- pause
复制代码
单个文件-重命名.bat- @echo off
- REM 1、下载 MediaInfo 这个命令行工具
- REM https://mediaarea.net/download/binary/mediainfo/23.10/MediaInfo_CLI_23.10_Windows_x64.zip
- REM 2、解压缩之后找到MediaInfo.exe、LIBCURL.DLL放在其中一个目录下:
- REM (1)跟 .bat 脚本放在同一个目录下
- REM (2)放在 C:\Windows\System32 目录下
-
- cd /d "%~dp0"
- set "OldName=input.mp4"
- for /f "tokens=4" %%i in ('mediainfo.exe "%OldName%" ^| findstr /b "Encoded date"') do (
- set "VideoEncodeDate=%%i"
- )
- ren "%OldName%" "%VideoEncodeDate%_%OldName%"
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |