Primo programmino, Classifica i files basato sull'estensione

« Older   Newer »
  Share  
Ikezawa
CAT_IMG Posted on 20/12/2010, 22:40     +1   -1




Il mio primo script giusto per giocare con autoit. Utilità dipende :P

Crea una cartella per ogni estensione trovata e vi trasferisce i relativi files
Ad esempio per classificare download in automatico

-Punta ad una cartella impostata dall'utente
-Ogni tot tempo X( Impostabile) riorganizza la cartella
-Salva la configurazione nei registri
-Se non ci sono sviste gestisce eventuali errori dovuti a registri cancellati
-Tutti i messaggi sono stile Traytip
-Ad ogni aggiornamento della cartella l'icona tray lampeggia
-Tempo da 1 a 60 min max
-Controllo input utente (limiti etcc)
-Controlla il percorso della cartella utente

-In base a determinate parole chave ( inputate dall'utente) crea una nuova cartella
non basandosi sull'estensione(non implementato)

:blink: lol

SPOILER (click to view)
CODICE
$timer = TimerInit()
$sec = 0
$min = 0

;Carica il percorso della cartella
$path = RegRead("HKEY_CURRENT_USER\Software\DownloadM\", "path")
if @error =0 Then
       
       $str = StringSplit($path, '\')        ;Cerca un "/"
       
       while  ($str[0]=1)                ;continua finchè non trova un "\"
               $path= FileSelectFolder("Seleziona la cartella dei tuoi download","",1, "")
               if @error=1 Then        ;se clicca su annulla
                       $return        = msgbox(4,"Impostazioni obbligaorie","La cartella attualmente non è impostata è impossibile quindi proseguire, vuoi uscire ?")
                       if $return=6 then Exit ; 6 = YES
               EndIf
               $str = StringSplit($path, '\')        ; assegna a str il valore della ricerca di "\"                                
       wend
       
       ;Se è tutto ok salva il percorso della cartella
       $success = RegWrite("HKEY_CURRENT_USER\Software\DownloadM", "path", "REG_SZ", $path)        
       
       if $success="" Then
               TrayTip("DownloadM","Cartella non salvata errore " & @error,10,3)
       Else
               TrayTip("DownloadM","Cartella impostata correttamente",10,1)
               sleep(2500)
       EndIf
Else
       RegWrite("HKEY_CURRENT_USER\Software\DownloadM", "path", "REG_SZ", "")
       TrayTip("DownloadM","Percorso cartella non caricato,Riparazione in corso...Uscita dal programma" ,10,3)
       
       
EndIf

$val_tmr = RegRead("HKEY_CURRENT_USER\Software\DownloadM\", "time")

if @error =0 Then
       if $val_tmr="" then
               TrayTip("DownloadM","Parametro errato . Impostato a 60s come default",20,2)
               $val_tmr=60 ; Valore di default
               RegWrite("HKEY_CURRENT_USER\Software\DownloadM", "Time", "REG_SZ", $val_tmr)
       Else
               TrayTip("DownloadM","Caricato parametro Time="& $val_tmr,20,1)
       EndIf        
Else
       TrayTip("DownloadM","Errore parametro Time,settato a 60s come default" ,10,3)
       $val_tmr=60 ; Valore di default
       RegWrite("HKEY_CURRENT_USER\Software\DownloadM", "Time", "REG_SZ", $val_tmr)
EndIf

$Error = FileChangeDir ( $path ) ;si sposta sulla cartella di lavoro
               if $Error =0 then
                       TrayTip("DownloadM","Impossibile settare il percorso..Continua",15,3)
               EndIf
               
Opt("TrayAutoPause",0)                ; Script Paused/exit visibili, script in run

$configura  = TrayCreateMenu("Configura")                                ; creazione di un menù sul system tray
$dir           = TrayCreateItem("Cartelle", $configura)
$cont           = TrayCreateItem("Imposta tempo", $configura)
TrayCreateItem("")
$www             = TrayCreateMenu("www")
$displayitem = TrayCreateItem("http://www.autoit.forumcommunity.net/", $www)

while 1
       

       TraySetToolTip("Time: " & $min & " min" & $sec &  " sec")

       $search = FileFindFirstFile("*.*")
       
       If $search = -1 Then
               MsgBox(0, "Error", "Non ci sono files nella cartella")
               Exit
       EndIf

       $menu = TrayGetMsg()

       if $menu = $dir then
               $pathtmp = FileSelectFolder("Seleziona la cartella dei tuoi download", "")
                $Error = FileChangeDir ( $pathtmp )
               if $Error =0 then
                       TrayTip("DownloadM","Percorso errato",20,2)
               Else
                       RegWrite("HKEY_CURRENT_USER\Software\DownloadM\", "path", "REG_SZ", $pathtmp)
                       $path=$pathtmp
                       TrayTip("DownloadM","Cartella impostata correttamente",10,1)
               EndIf                                        
       EndIf        
                       
       if $menu = $cont then
               $val_tmr = InputBox ("Ogni tot minuti DownloadM aggiornerà la cartella utente", "Quanti minuti (max 60)","","",150,150)
               if $val_tmr >60 or $val_tmr = 0 then  
                       TrayTip("DownloadM","Parametro errato ,(da 1 a 60)",20,2)
               Else
                       TrayTip("DownloadM","Tempo=" & $val_tmr & "minuto",10,1)
                       RegWrite("HKEY_CURRENT_USER\Software\DownloadM", "Time", "REG_SZ", $val_tmr)
               EndIf        
       EndIf

       if $menu  = $www Then ShellExecute("http://autoit.forumcommunity.net/")
                               
       if TimerDiff($timer) > 999 Then
               $sec += 1
               $timer = TimerInit()        
       EndIf
       if $sec = 60 Then
               $min += 1
               $sec = 0
       EndIf

       if $min = $val_tmr Then        ;temporizzatore
               $min =0
               TraySetState(4)
               while 1
       
                       $file = FileFindNextFile($search)
                       If @error Then
                               sleep(3000)
                               ExitLoop        
                       EndIf
                       $array = StringSplit($file, '.')
                       $max = ubound ($array,1)
                       ;per il file senza estensione non crea cartella
                       if        ($max-1)>0 then
                               DirCreate($array[$max-1])
                               If FileExists($path & "\*."& $array[$max-1]) Then filemove($path & "\*." & $array[$max-1],$path & "\" & $array[$max-1],1)
                       EndIf        
               WEnd
               TraySetState(8)
       EndIf        

WEnd


Edited by Aaly - 21/12/2010, 16:32
 
Top
xMasteRx
CAT_IMG Posted on 21/12/2010, 01:12     +1   -1




questo è il tuo primo script in autoit? :blink: wow cominci bene eh XD
molto buono ^^
 
Top
Ikezawa
CAT_IMG Posted on 21/12/2010, 01:36     +1   -1




Thanks :P
 
Top
T3rrorisT
CAT_IMG Posted on 21/12/2010, 12:40     +1   -1




bravissimo! finalmente uno che non inizia con la solita calcolatrice XD Cmq sicuro che sia il primo script? XD sembra molto complicato per uno che ha appena iniziato XD
 
Top
Aaly
CAT_IMG Posted on 21/12/2010, 16:33     +1   -1




Ti ho messo il codice sotto spoiler, comunque bravo! Utile ^^
 
Top
Ikezawa
CAT_IMG Posted on 21/12/2010, 19:27     +1   -1




una versione precedente che identifica solo quattro estensioni è presente su un altro forum(postato 1 settimana fa).Comunque si è il mio primo script in Autoit :P
 
Top
Ikezawa
icon4  CAT_IMG Posted on 23/12/2010, 01:52     +1   -1




Già che c'ero ho fatto una versione che legge da un file le parole chiave da ricercare
nei nomi dei file per organizzarli in cartelle.
Il nome della cartella dipende dalla parola chiave
esempio di file di configurazione:
CODICE
=c:\download\installer=;setup;install;ciccio;
=c:\download\documenti=;autoit;visualc;cplus;
=c:\download\corsi=;pino;seeyou;corso;
=c:\download\vari=;auto;inj;php;


è giusto una base , non ci sono menù ed il tempo e la cartella di lavoro si
settano a mano nel codice :unsure:
SPOILER (click to view)
$timer = TimerInit()
$sec = 0
$min = 0


$path ="C:\Download"
$val_tmr = 60

Opt("TrayAutoPause",0) ; Script Paused/exit visibili, script in run


$Error = FileChangeDir ( $path ) ;si sposta sulla cartella di lavoro
if $Error =0 then
TrayTip("DownloadM","Impossibile settare il percorso..Continua",15,3)
Exit
EndIf

$search = FileFindFirstFile("*.*") ; Inizia una nuova ricerca all'interno della cartella corrente
$filterFile = FileOpen("filterDwt", 0) ;Apre in lettura il file di configurazione delle keyword
$text = FileReadLine($filterFile) ;Inializza le tre variabili per il primo ciclo
$folder =StringSplit($text,"=")
$keys = StringSplit($text,";")

while 1
if TimerDiff($timer) > 999 Then
$sec += 1
$timer = TimerInit()
EndIf
if $sec = 60 Then
$min += 1
$sec = 0
EndIf

if $min =$val_tmr Then ;temporizzatore
$min =0

while 1
$file = FileFindNextFile($search)
If @error Then ; controllati tutti file della cartella

FileClose($search)
exit
EndIf

$array = StringSplit($file, '.') ;Inizia analisi file
$max = ubound ($array,1)
;per il file senza estensione non crea cartella
if ($max-1)>1 then

while 1
$id=0 ;Indice array
$found=0 ;Flag segnala corrispondenza trovata

while($id < $keys[0]) ;Scannerizza l'intero array per ogni elemento fino alla fine
$id+=1 ;incrementa passa alla prossima occorenza travata nel file di configurazione ( SOPRA)
$results = StringInStr($array[1],$keys[$id],0) ; cerca nel nome del file corrente una corrispondenza con le keyword di configurazione
if $results<>0 then ;in caso di successo
FileMove($path & "\" & $file,$folder[2] & "\" & $file,8) ; trasferisce il file corrente nella cartella appena creata con la path associata di configurazione
$found =1
EndIf
WEnd

$text = FileReadLine($filterFile) ;Prossima riga di keyword per questo file
$folder =StringSplit($text,"=")
$keys = StringSplit($text,";")

if @error<>0 then
fileclose($filterFile)
$filterFile = FileOpen("filterDwt", 0) ;Apre in lettura il file di configurazione delle keyword
$text = FileReadLine($filterFile) ;Prossima riga di keyword per questo file
$folder =StringSplit($text,"=")
$keys = StringSplit($text,";")
ExitLoop
EndIf
wend
EndIf
WEnd
EndIf
wend


:sick:
 
Top
6 replies since 20/12/2010, 22:40   212 views
  Share