I'm new to autoit scripting so please bare with me...
this is my Search function which searches local drives for .PST files and if any are found they are copied to /My Documents/PST/ directory although I had some issues with PST files that are the same filename so I needed to implement some auto rename & add '1' to end of filename.. this kinda works but sometimes it makes too many copies of the same .PST files when auto-renaming
For example, theres 2 archive.pst files with same filename so its suppose to rename only one file to archive(1).pst and thats it..although its making more duplicates: archive(1).pst, archive(1)(1).pst, archive(1)(1)(1).pst..
maybe someone can help me clean it up and work properly
Func Search($current) Local $search = FileFindFirstFile($current & "\*.*") While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop ;Add pst / pab files to the array and backup If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") and Not StringInStr($current & "\" & $file, $pstdest) And ($file <> "." Or $file <> "..") And StringRight($file, 3) = "pst" or StringRight($file, 3) = "pab" Then $filexists = $pstdest & $file If FileExists ($filexists) Then $position = StringInStr($filexists, '.', 0, -1) $filename = StringLeft($filexists, $position -1) $extension = StringMid($filexists, $position) For $i = 1 To 1000000 $newfilename = $filename & "(" & $i & ")" & $extension If FileCopy($filexists, $newfilename) Then ExitLoop Next MsgBox(4096,"PST FILENAME DUPLICATE", "Original PST: " & $filexists & " New PST Filename: " & $newfilename, 10) $result = 3 ;dont ask Else $result = FileCopyP($current & "\" & $file, $pstdest) EndIf ;Write to log file. If $result = 1 Then _FileWriteLog($backupdest&"\" & "pstlog.log", "BACKUP SUCCESS: " & $current & "\" & $file) ElseIf $result = 3 Then _FileWriteLog($backupdest&"\" & "pstlog.log", "**RENAME** BACKUP SUCCESS: " & $current & "\" & $file & " RENAMED TO: " & $newfilename) Else _FileWriteLog($backupdest&"\" & "pstlog.log", "**FAIL** BACKUP FAILURE: " & $current & "\" & $file) Endif EndIf If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") AND StringInStr($current & "\" & $file, $pstdest) = 0 Then Search($current & "\" & $file) EndIf WEnd FileClose($search) EndFunc







