Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Auto file copier

$
0
0

Hi

I'm a newbie and I need a help with these codes.

I want to edit it to copy specific file formats.

Can anyone direct me how to edit it and what should be replaced.

Thanks

AutoIt         
HotKeySet("!^+q", "MyExit")  ;Alt+Ctrl+Shift+q $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" Dim $MyDrives[1] $MyDrives[0] = 0 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $m_MediaConnectWatcher = $objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive'") While 1     $mbo = $m_MediaConnectWatcher.NextEvent     $obj = $mbo.TargetInstance     If $obj.InterfaceType == "USB" Then         $New = GetDriveLetterFromDisk($obj.Name)         $Label = DriveGetLabel($New)         For $i = 1 to $MyDrives[0]             If $Label == $MyDrives[$i] Then ContinueLoop 2         Next         BackUp($New,$Label)         ContinueLoop     EndIf WEnd Func MyExit()     Exit EndFunc Func BackUp($drive,$label)     $now = StringReplace(_NowCalc(),":","")     $now = StringReplace($now,"/","")     $now = StringReplace($now," ","")     $path = FileReadLine("path.txt",1)     If @error Then $path = "C:\flashbackup\"     If Not StringRight($path,1) == "\" Then $path &= "\"     $FileList = RecursiveFileSearch($drive)     Dim $FilesOnly[1][2]     $FilesOnly[0][0] = 0     For $i = 1 to $FileList[0]         If StringInStr(FileGetAttrib($FileList[$i]), "D") > 0 Then ContinueLoop         $FilesOnly[0][0] += 1         ReDim $FilesOnly[$FilesOnly[0][0]+1][2]         $FilesOnly[$FilesOnly[0][0]][0] = $FileList[$i]         $FilesOnly[$FilesOnly[0][0]][1] = FileGetSize($FileList[$i])     Next     _ArraySort($FilesOnly,0,0,0,1)     For $i = 1 to $FilesOnly[0][0]         $src = $FilesOnly[$i][0]         $dest = $path & StringReplace($drive,":","") & "_" & $label & "_" & $now & StringTrimLeft($src,2)         FileCopy($src,$dest,9)     Next EndFunc Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = true, $RFSdepth = 0)    ;Ensure starting folder has a trailing slash      If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"      If $RFSdepth = 0 Then        ;Get count of all files in subfolders for initial array definition          $RFSfilecount = DirGetSize($RFSstartDir, 1)        ;File count + folder count (will be resized when the function returns)         If IsArray($RFSfilecount) Then             Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]         Else             SetError(1)             Return         EndIf      EndIf      $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")      If @error Then Return    ;Search through all files and folders in directory      While 1          $RFSnext = FileFindNextFile($RFSsearch)          If @error Then ExitLoop        ;If folder and recurse flag is set and regex matches          If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then              If $RFSrecurse AND StringRegExp($RFSnext, $RFSFolderpattern, 0) Then                  RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)                  If $RFSFlag <> 1 Then                    ;Append folder name to array                      $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext                      $RFSarray[0] += 1                  EndIf              EndIf          ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) AND $RFSFlag <> 2 Then            ;Append file name to array              $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext              $RFSarray[0] += 1          EndIf      WEnd      FileClose($RFSsearch)      If $RFSdepth = 0 Then          Redim $RFSarray[$RFSarray[0] + 1]          Return $RFSarray      EndIf EndFunc ;==>RecursiveFileSearch  Func GetDriveLetterFromDisk($name)     $ans = ""     $name = StringReplace($name,"\","\\")     $oq_part = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $name & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)     If IsObj($oq_part) Then         For $obj_part In $oq_part             $oq_disk = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $obj_part.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)             If IsObj($oq_disk) Then                 For $obj_disk in $oq_disk                     $ans = $ans & $obj_disk.Name                 Next             EndIf         Next     EndIf     Return $ans EndFunc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>