找回密码
 加入
搜索
查看: 1942|回复: 1

[效率算法] 关于复制并重命名问题(已解决)

[复制链接]
发表于 2010-10-9 12:52:25 | 显示全部楼层 |阅读模式
本帖最后由 shenrenba 于 2010-10-11 09:48 编辑

下面代码中我就是把歌重新复制并重命名  文件一旦多 则大部分都是命名不全(一般都是没后缀和歌曲名)  该如何解决 还是我代码有问题?
#include <File.au3>
$path = @UserProfileDir & "\Local Settings\Temporary Internet Files"
$search = findfile($path)
Func findfile($path)
        $aFileList = _FileListToArray($path)
        If Not @error Then
                For $i = 1 To $aFileList[0]
                        findfile($path & '\' & $aFileList[$i])
                        If StringRight($path & '\' & $aFileList[$i], 4) = '.mp3' Then
                                $mp3info = _GetMp3info($path & '\' & $aFileList[$i])
                                If Not @error Then
                                        $mp3people = StringRegExpReplace($mp3info[1], '\s+', '')
                                        $mp3name = StringRegExpReplace($mp3info[0], '\s+', '')
                                        ;FileMove($path & '\' & $aFileList[$i], "D:\123" & $mp3people & "-" & $mp3name & ".mp3", 9)
                                        FileCopy($path & '\' & $aFileList[$i], "D:\123" & $mp3people & "-" & $mp3name & ".mp3", 9)
                                Else
                                        ;FileMove($path & '\' & $aFileList[$i], "D:\123", 9)
                                        FileCopy($path & '\' & $aFileList[$i], "D:\123", 9)
                                EndIf
                        EndIf
                Next
        EndIf
EndFunc   ;==>findfile

Func _GetMp3info($nFile)
        $hFile = FileOpen($nFile, 0)
        If $hFile = -1 Then
                SetError(1)
                Return ""
        Else
                FileSetPos($hFile, -128, 2)
                $bBuffer = FileRead($hFile, 128)
                If BinaryToString(BinaryMid($bBuffer, 1, 3)) = "TAG" Then
                        Local $TMPARRAY[4]
                        $TMPARRAY[0] = BinaryToString(BinaryMid($bBuffer, 4, 30))
                        $TMPARRAY[1] = BinaryToString(BinaryMid($bBuffer, 34, 30))
                        $TMPARRAY[2] = BinaryToString(BinaryMid($bBuffer, 64, 30))
                        $TMPARRAY[3] = BinaryToString(BinaryMid($bBuffer, 94, 4))
                        Return $TMPARRAY
                Else
                        SetError(2)
                        Return ""
                EndIf
        EndIf
        FileClose($hFile)
EndFunc   ;==>_GetMp3info
发表于 2010-10-9 13:31:25 | 显示全部楼层
看似字符串,其实不是。
#include <File.au3>
$path = @UserProfileDir & "\Local Settings\Temporary Internet Files"
$search = findfile($path)
Func findfile($path)
        $aFileList = _FileListToArray($path)
        If Not @error Then
                For $i = 1 To $aFileList[0]
                        findfile($path & '\' & $aFileList[$i])
                        If StringRight($path & '\' & $aFileList[$i], 4) = '.mp3' Then
                                $mp3info = _GetMp3info($path & '\' & $aFileList[$i])                                                        
;~                                                                 If IsArray($mp3info) Then MsgBox(0,0,String($mp3info[1])&string($mp3info[0]))
                                If Not @error Then
                                        $mp3people = StringRegExpReplace(String($mp3info[1]), '\s+', '')
                                        $mp3name = StringRegExpReplace(String($mp3info[0]), '\s+', '')
                                        ;FileMove($path & '\' & $aFileList[$i], "D:\123\" & $mp3people & "-" & $mp3name & ".mp3", 9)
                                        FileCopy($path & '\' & $aFileList[$i], "D:\123\" & $mp3people & "-" & $mp3name & ".mp3", 9)
                                Else
                                        ;FileMove($path & '\' & $aFileList[$i], "D:\123\", 9)
                                        FileCopy($path & '\' & $aFileList[$i], "D:\123\", 9)
                                EndIf
                        EndIf
                Next
        EndIf
EndFunc   ;==>findfile

Func _GetMp3info($nFile)
        $hFile = FileOpen($nFile, 0)
        If $hFile = -1 Then
                SetError(1)
                Return ""
        Else
                FileSetPos($hFile, -128, 2)
                $bBuffer = FileRead($hFile, 128)
                If BinaryToString(BinaryMid($bBuffer, 1, 3)) = "TAG" Then
                        Local $TMPARRAY[4]
                        $TMPARRAY[0] = BinaryToString(BinaryMid($bBuffer, 4, 30))
                        $TMPARRAY[1] = BinaryToString(BinaryMid($bBuffer, 34, 30))
                        $TMPARRAY[2] = BinaryToString(BinaryMid($bBuffer, 64, 30))
                        $TMPARRAY[3] = BinaryToString(BinaryMid($bBuffer, 94, 4))
                        Return $TMPARRAY
                Else
                        SetError(2)
                        Return ""
                EndIf
        EndIf
        FileClose($hFile)
EndFunc   ;==>_GetMp3info

评分

参与人数 1金钱 +20 贡献 +3 收起 理由
shenrenba + 20 + 3

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-9 12:59 , Processed in 0.094377 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表