安卓手机拍照、截图的图片文件都比较有规则,这里做进一步处理,只以年月日时分秒作为文件名。不规则命名的就读取文件元数据进行命名。
自用,没有通用性,参考请谨慎
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
#include <File.au3> #include <MsgBoxConstants.au3> $Path = "C:/Users/Administrator/Desktop/pi"; getFiles() Func getFiles() Local $aFileList = _FileListToArray($Path, "*", 1, False) ; False不返回绝对路径,True返回 If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "路径无效.") Exit EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "未发现文件.") Exit EndIf For $i = 1 To UBound($aFileList) - 1 $file = $aFileList[$i] ConsoleWrite($file & @CRLF) $type = StringSplit($file, ".")[2] $name = getName($file) $name = comLen($name) ConsoleWrite($name & @CRLF) ;FileMove($Path & "/" & $file, $Path & "/" & $name & "." & $type) Next EndFunc Func getName($file1) $start1 = StringLeft ( $file1, 3 ) $compare1 = StringCompare($start1, "IMG", 0) $start2 = StringLeft ( $file1, 10 ) $compare2 = StringCompare($start2, "Screenshot", 0) $start3 = StringLeft ( $file1, 4 ) $compare3 = StringCompare($start3, "PANO", 0) If $compare1 = 0 Or $compare2 = 0 Or $compare3 = 0 Then Return StringRegExpReplace($file1, '[^\d]', '') Else Return prty($file1) EndIf EndFunc Func prty($file2) $filesystem = ObjCreate("scripting.filesystemobject") $fileinstance = $filesystem.GetFile($Path & "/" & $file2) $filename = $fileinstance.Name $filepath = $fileinstance.ParentFolder.Path $application = ObjCreate("Shell.Application") $shell = $application.Namespace($filepath) $item = $shell.Items.Item($filename) Local $aArray[2][2] $aArray[0][0] = "修改日期" $aArray[1][0] = "创建日期" Local $key Local $value For $i = 0 To 30 $detail = $shell.GetDetailsOf($item, $i) If StringLen($detail) > 0 Then $key = $shell.GetDetailsOf(0, $i) $value = $shell.GetDetailsOf($item, $i) If "拍摄日期" = $key Then ; 如果首先读到了拍摄日期就使用之 $value = str2time($value) ExitLoop Else ; 实际先读创建日期和修改日期 If "修改日期" = $key Then $aArray[0][1] = $value EndIf If "创建日期" = $key Then $aArray[1][1] = $value EndIf If "" <> $aArray[0][1] And "" <> $aArray[1][1] Then $v1 = str2time($aArray[0][1]) $v2 = str2time($aArray[1][1]) If $v1 < $v2 Then $value = $v1 Else $value = $v2 EndIf ;ExitLoop EndIf EndIf EndIf Next Return $value EndFunc Func str2time($str = "") $split = StringSplit($str, ",") $ymd = StringSplit($split[2], "/") $year = "20" & $ymd[1] $month = $ymd[2] If $month < 10 Then $month = "0" & $ymd[2] EndIf $day = "" & $ymd[3] $dsfm = StringSplit($day, " ") If $dsfm[1] < 10 Then $day = "0" & $dsfm[1] EndIf Return StringRegExpReplace($year & $month & $day & $dsfm[2], '[^\d]', '') EndFunc Func comLen($name1 = "") $len = StringLen($name1) If $len < 16 Then $count = 16 - $len $tmpstr = "" For $i = 0 To $count - 1 $tmpstr = $tmpstr & "0" Next $name1 = $name1 & $tmpstr EndIf Return $name1 EndFunc |
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/2160.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设