Metal Posted June 6, 2009 Share Posted June 6, 2009 Hi I just finished to code a new program, but when i try to execute it, Scite give me this error: (125) : ==> "EndSwitch" statement with no matching "Switch" statement.: EndSwitch This is the code, it's a bit long. I really can't find the error. expandcollapse popupWhile 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Exit Exit Case $Settings _settings() Case $Button1 $path = FileSelectFolder("Selezionare la cartella","") If $path = "" Then ContinueLoop Else GUICtrlSetData($Input1,$path) EndIf Case $Button2 $path1 = FileSelectFolder("Selezionare la cartella","") If $path1 = "" Then ContinueLoop Else GUICtrlSetData($Input2,$path1) EndIf Case $Button3 ;origine If GUICtrlRead($Input1) <> '' Then GUICtrlSetData($Label3,'Stato: creazione lista origine...') _fileListOr() GUICtrlSetState($Button3,$GUI_ENABLE) GUICtrlSetData($Label3,'Stato: in attesa') Else MsgBox(48,"Errore","Non è stata selezionata una cartella di origine.") ContinueLoop EndIf ;destinazione If GUICtrlRead($Input2) <> '' Then GUICtrlSetData($Label3,'Stato: creazione lista destinazione...') $diststate = _fileListDest() GUICtrlSetData($Label3,'Stato: in attesa') If $diststate = 1 Then GUICtrlSetData($Label3,'Stato: in attesa') ElseIf $diststate = 2 Then GUICtrlSetData($Label3,'Stato: in attesa') MsgBox(64,"Finito!","Il backup è stato eseguito con successo!") Else _cutPathAddress() GUICtrlSetData($Label3,'Stato: comparazione liste...') _compareLists() GUICtrlSetData($Label3,'Stato: in attesa') If $diff[0][0] <> 0 Then;file da aggiornare $wtd = MsgBox(4+48,"File da aggiornare","Sono stati trovati "&$diff[0][0]&" file da aggiornare."&@CRLF&"Eseguire l'aggiornamento?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: aggiornamento file...') _updateFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $new[0][0] <> 0 Then;file nuovi $wtd = MsgBox(4+48,"File nuovi","Sono stati trovati "&$new[0][0]&" nuovi file."&@CRLF&"Aggiungerli al backup?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: salvataggio nuovi file...') _addFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $old[0] <> 0 Then;file vecchi $wtd = MsgBox(4+48,"File vecchi","Sono stati trovati "&$old[0]&" file non più presenti nella cartella d'origine."&@CRLF&"Eliminarli?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: cancellazione file vecchi...') _deleteFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $diff[0][0] = 0 AND $new[0][0] = 0 AND $old[0][0] = 0 Then MsgBox(64,"","I file presenti nella cartella di destinazione sono già aggiornati.") MsgBox(64,"Finito!","Il backup è stato eseguito con successo!") EndIf Else MsgBox(48,"Errore","Non è stata selezionata una cartella di destinazione.") ContinueLoop EndIf EndSwitch WEnd Link to comment Share on other sites More sharing options...
Inverted Posted June 7, 2009 Share Posted June 7, 2009 That's not the whole code ... post a fully working test sample plz. Link to comment Share on other sites More sharing options...
Metal Posted June 7, 2009 Author Share Posted June 7, 2009 it's really long expandcollapse popup#include <GUIConstants.au3> #include <EditConstants.au3> #include <FileToArray.au3> #include <Array.au3> $Form1 = GUICreate("Backup To HD", 346, 226, 193, 125) GUISetBkColor(0xFF9900,$Form1) $Label1 = GUICtrlCreateLabel("Origine:", 48, 64, 40, 17) $Label2 = GUICtrlCreateLabel("Destinazione:", 24, 112, 68, 17) $Label3 = GUICtrlCreateLabel("Stato: in attesa", 120, 144, 150, 17) $Input1 = GUICtrlCreateInput("", 104, 56, 193, 21, $ES_READONLY) $Input2 = GUICtrlCreateInput("", 104, 104, 193, 21, $ES_READONLY) $Button1 = GUICtrlCreateButton("...", 304, 56, 17, 17, 0) $Button2 = GUICtrlCreateButton("...", 304, 104, 17, 17, 0) $Button3 = GUICtrlCreateButton("Backup!", 120, 176, 137, 33, 0) $Menu = GUICtrlCreateMenu("File") $Settings = GUICtrlCreateMenuItem("Impostazioni",$Menu) GUICtrlCreateMenuItem("",$Menu) $Exit = GUICtrlCreateMenuItem("Esci",$Menu) GUISetState(@SW_SHOW) Global $path Global $path1 Global $files[100000][2] Global $dir[100000] Global $files1[100000][2] Global $dir1[100000] Global $diff[100000][2];indirizzi file con data di modifica diversa Global $new[100000][2];indirizzi sul pc dei file nuovi Global $old[100000];indirizzi sul HD di file vecchi - non serve il tempo perché andranno cancellati Global $tfiles Global $tdir $files[0][0] = 0 $files1[0][0] = 0 $dir[0] = 0 $dir1[0] = 0 $alwaysOverwrite = INIRead(@ScriptDir & "\settings.ini","settings","alwaysOverwrite","errore") $alwaysAdd = INIRead(@ScriptDir & "\settings.ini","settings","alwaysAdd","errore") $alwaysRemove = INIRead(@ScriptDir & "\settings.ini","settings","alwaysRemove","errore") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Exit Exit Case $Settings _settings() Case $Button1 $path = FileSelectFolder("Selezionare la cartella","") If $path = "" Then ContinueLoop Else GUICtrlSetData($Input1,$path) EndIf Case $Button2 $path1 = FileSelectFolder("Selezionare la cartella","") If $path1 = "" Then ContinueLoop Else GUICtrlSetData($Input2,$path1) EndIf Case $Button3 ;origine If GUICtrlRead($Input1) <> '' Then GUICtrlSetData($Label3,'Stato: creazione lista origine...') _fileListOr() GUICtrlSetState($Button3,$GUI_ENABLE) GUICtrlSetData($Label3,'Stato: in attesa') Else MsgBox(48,"Errore","Non è stata selezionata una cartella di origine.") ContinueLoop EndIf ;destinazione If GUICtrlRead($Input2) <> '' Then GUICtrlSetData($Label3,'Stato: creazione lista destinazione...') $diststate = _fileListDest() GUICtrlSetData($Label3,'Stato: in attesa') If $diststate = 1 Then GUICtrlSetData($Label3,'Stato: in attesa') ElseIf $diststate = 2 Then GUICtrlSetData($Label3,'Stato: in attesa') MsgBox(64,"Finito!","Il backup è stato eseguito con successo!") Else _cutPathAddress() GUICtrlSetData($Label3,'Stato: comparazione liste...') _compareLists() GUICtrlSetData($Label3,'Stato: in attesa') If $diff[0][0] <> 0 Then;file da aggiornare $wtd = MsgBox(4+48,"File da aggiornare","Sono stati trovati "&$diff[0][0]&" file da aggiornare."&@CRLF&"Eseguire l'aggiornamento?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: aggiornamento file...') _updateFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $new[0][0] <> 0 Then;file nuovi $wtd = MsgBox(4+48,"File nuovi","Sono stati trovati "&$new[0][0]&" nuovi file."&@CRLF&"Aggiungerli al backup?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: salvataggio nuovi file...') _addFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $old[0] <> 0 Then;file vecchi $wtd = MsgBox(4+48,"File vecchi","Sono stati trovati "&$old[0]&" file non più presenti nella cartella d'origine."&@CRLF&"Eliminarli?") If $wtd = 6 Then GUICtrlSetData($Label3,'Stato: cancellazione file vecchi...') _deleteFiles() EndIf EndIf GUICtrlSetData($Label3,'Stato: in attesa') If $diff[0][0] = 0 AND $new[0][0] = 0 AND $old[0][0] = 0 Then MsgBox(64,"","I file presenti nella cartella di destinazione sono già aggiornati.") MsgBox(64,"Finito!","Il backup è stato eseguito con successo!") EndIf Else MsgBox(48,"Errore","Non è stata selezionata una cartella di destinazione.") ContinueLoop EndIf EndSwitch WEnd #cs Func _settings() EndFunc #ce Func _directCopy() $len = StringLen($path) For $i = 1 To $files[0][0] $files[$i][0] = StringTrimLeft($files[$i][0],$len) Next For $i = 1 To $files[0][0] FileCopy($path & $files[$i][0], $path1 & $files[$i][0],9) FileSetTime($path1,$files[$i][1]) Next EndFunc Func _deleteFiles() For $i = 1 To $old[0] FileRecycle($path1 & $old[$i]) Next EndFunc Func _addFiles() For $i = 1 To $new[0][0] $a = FileCopy($path & $new[$i][0], $path1 & $new[$i][0],9) FileSetTime($path1 & $new[$i][0], $new[$i][1]) Next EndFunc Func _updateFiles() For $i = 1 To $diff[0][0] FileCopy($path & $diff[$i][0], $path1 & $diff[$i][0],1) FileSetTime($path1 & $diff[$i][0], $diff[$i][1]) Next EndFunc Func _cutPathAddress() $len = StringLen($path) $len1 = StringLen($path1) For $i = 1 To $files[0][0] $files[$i][0] = StringTrimLeft($files[$i][0],$len) Next For $i = 1 To $dir[0] $dir[$i] = StringTrimLeft($dir[$i],$len) Next For $i = 1 To $files1[0][0] $files1[$i][0] = StringTrimLeft($files1[$i][0],$len1) Next For $i = 1 To $dir1[0] $dir1[$i] = StringTrimLeft($dir1[$i],$len1) Next EndFunc Func _compareLists() $k = 0 For $i = 1 To $files[0][0] For $j = 1 To $files1[0][0] If $files[$i][0] = $files1[$j][0] Then If $files[$i][1] <> $files1[$j][1] Then $k = $k + 1 $diff[$k][0] = $files[$i][0] $diff[$k][1] = $files[$i][1] ExitLoop EndIf EndIf Next Next $diff[0][0] = $k $k = 0 For $i = 1 To $files[0][0] $state = false For $j = 1 To $files1[0][0] If $files[$i][0] = $files1[$j][0] Then $state = true ExitLoop EndIf Next If $state = false Then $k = $k + 1 $new[$k][0] = $files[$i][0] $new[$k][1] = $files[$i][1] EndIf Next $new[0][0] = $k $k = 0 For $j = 1 To $files1[0][0] $state = false For $i = 1 To $files[0][0] If $files1[$j][0] = $files[$i][0] Then $state = true ExitLoop EndIf Next If $state = false Then $k = $k + 1 $old[$k] = $files1[$j][0] EndIf Next $old[0] = $k EndFunc Func _fileListOr() $tfiles = _FileListToArrayEx($path,'*.*',1,'') If @error = 1 Then MsgBox(48,"Errore","Cartella di origine non trovata o invalida.") Return EndIf If IsArray($tfiles) Then For $i = 0 To $tfiles[0] If $i = $tfiles[0] Then $files[0][0] = $i ExitLoop EndIf $files[$i+1][0] = $tfiles[$i+1] $files[$i+1][1] = FileGetTime($tfiles[$i+1],0,1) Next _deleteArray('files') EndIf $tdir = _FileListToArrayEx($path,'*',2,'') If @error = 1 Then MsgBox(48,"Errore","Cartella di origine non trovata o invalida.") Return EndIf If IsArray($tdir) Then For $i = 0 To $tdir[0] If $i = $tdir[0] Then $dir[0] = $i ExitLoop EndIf $dir[$i+1] = $tdir[$i+1] Next _deleteArray('dir') EndIf $j = 1 While 1 $tdir = _FileListToArrayEx($dir[$j],'*',2,'') If IsArray($tdir) Then For $i = 0 To $tdir[0] If $i = $tdir[0] Then $dir[0] = $dir[0] + $i ExitLoop EndIf $dir[1+$i+$dir[0]] = $tdir[$i+1] Next _deleteArray('dir') EndIf $j = $j + 1 If $j > $dir[0] Then ExitLoop EndIf WEnd For $j = 1 To $dir[0] $tfiles = _FileListToArrayEx($dir[$j],'*.*',1,'') If IsArray($tfiles) Then For $i = 0 To $tfiles[0] If $i = $tfiles[0] Then $files[0][0] = $files[0][0] + $i ExitLoop EndIf $files[1+$i+$files[0][0]][0] = $tfiles[$i+1] $files[1+$i+$files[0][0]][1] = FileGetTime($tfiles[$i+1],0,1) Next _deleteArray('files') EndIf Next EndFunc Func _fileListDest() $tfiles = _FileListToArrayEx($path1,'*.*',1,'') If @error = 1 Then MsgBox(48,"Errore","Cartella di destinazione non trovata o invalida.") Return EndIf $xyz = 0 If @error = 4 Then $xyz = 1 EndIf If IsArray($tfiles) Then For $i = 0 To $tfiles[0] If $i = $tfiles[0] Then $files1[0][0] = $i ExitLoop EndIf $files1[$i+1][0] = $tfiles[$i+1] $files1[$i+1][1] = FileGetTime($tfiles[$i+1],0,1) Next _deleteArray('files') EndIf SetError(0) $tdir = _FileListToArrayEx($path1,'*',2,'') If @error = 1 Then MsgBox(48,"Errore","Cartella di destinazione non trovata o invalida.") Return EndIf $xyz1 = 0 If IsArray($tdir) AND ($tdir[0] <> 1) AND ($tdir[1] <> $path1 & '\') Then For $i = 0 To $tdir[0] If $i = $tdir[0] Then $dir1[0] = $i ExitLoop EndIf $dir1[$i+1] = $tdir[$i+1] Next _deleteArray('dir') Else $xyz1 = 1 EndIf If ($xyz = 1) AND ($xyz1 = 1) Then $ask = MsgBox(4+48,"Nessun file","Nessun file trovato nella cartella di destinazione."&@CRLF&"Eseguire una copia diretta?") If $ask = 6 Then GUICtrlSetData($Label3,'Stato: backup in corso...') _directCopy() Return 2 Else MsgBox(48,"Abortito","Backup abortito.") Return 1 EndIf EndIf $j = 1 While 1 $tdir = _FileListToArrayEx($dir1[$j],'*',2,'') If IsArray($tdir) Then For $i = 0 To $tdir[0] If $i = $tdir[0] Then $dir1[0] = $dir1[0] + $i ExitLoop EndIf $dir1[1+$i+$dir1[0]] = $tdir[$i+1] Next _deleteArray('dir') EndIf $j = $j + 1 If $j > $dir1[0] Then ExitLoop EndIf WEnd For $j = 1 To $dir1[0] $tfiles = _FileListToArrayEx($dir1[$j],'*.*',1,'') If IsArray($tfiles) Then For $i = 0 To $tfiles[0] If $i = $tfiles[0] Then $files1[0][0] = $files1[0][0] + $i ExitLoop EndIf $files1[1+$i+$files1[0][0]][0] = $tfiles[$i+1] $files1[1+$i+$files1[0][0]][1] = FileGetTime($tfiles[$i+1],0,1) Next _deleteArray('files') EndIf Next EndFunc Func _deleteArray($which) If $which = 'files' Then For $i = ($tfiles[0] + 1) To 0 Step -1 _ArrayDelete($tfiles,$i) Next ElseIf $which = 'dir' Then For $i = ($tdir[0] + 1) To 0 Step -1 _ArrayDelete($tdir,$i) Next EndIf EndFunc you also need FileToArray.au3 expandcollapse popup;=============================================================================== ; ; Description: lists all or preferred files and or folders in a specified path (Similar to using Dir with the /B Switch) ; Syntax: _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '') ; Parameter(s): $sPath = Path to generate filelist for ; $sFilter = The filter to use. Search the Autoit3 manual for the word "WildCards" For details, support now for multiple searches ; Example *.exe; *.txt will find all .exe and .txt files ; $iFlag = determines weather to return file or folders or both. ; $sExclude = exclude a file from the list by all or part of its name ; Example: Unins* will remove all files/folders that start with Unins ; $iFlag=0(Default) Return both files and folders ; $iFlag=1 Return files Only ; $iFlag=2 Return Folders Only ; ; Requirement(s): None ; Return Value(s): On Success - Returns an array containing the list of files and folders in the specified path ; On Failure - Returns the an empty string "" if no files are found and sets @Error on errors ; @Error or @extended = 1 Path not found or invalid ; @Error or @extended = 2 Invalid $sFilter or Invalid $sExclude ; @Error or @extended = 3 Invalid $iFlag ; @Error or @extended = 4 No File(s) Found ; ; Author(s): SmOke_N ; Note(s): The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Files\Folders returned ; $array[1] = 1st File\Folder ; $array[2] = 2nd File\Folder ; $array[3] = 3rd File\Folder ; $array[n] = nth File\Folder ; ; All files are written to a "reserved" .tmp file (Thanks to gafrost) for the example ; The Reserved file is then read into an array, then deleted ;=============================================================================== Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False) If Not FileExists($sPath) Then Return SetError(1, 1, '') If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*' If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0 If $sExclude = -1 Or $sExclude = Default Then $sExclude = '' Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|'] $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';') If StringRight($sPath, 1) <> '\' Then $sPath &= '\' For $iCC = 0 To 5 If StringInStr($sFilter, $aBadChar[$iCC]) Or _ StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '') Next If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '') If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '') Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder $sTFolder = $oFSO.GetSpecialFolder(2) Local $hOutFile = @TempDir & $oFSO.GetTempName If Not StringInStr($sFilter, ';') Then $sFilter &= ';' Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit For $iCC = 1 To $aSplit[0] If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop If StringLeft($aSplit[$iCC], 1) = '.' And _ UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC] $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" ' Next $sHoldSplit = StringTrimRight($sHoldSplit, 1) If $iRecurse Then RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE) Else RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE) EndIf $sRead &= FileRead($hOutFile) If Not FileExists($hOutFile) Then Return SetError(4, 4, '') FileDelete($hOutFile) If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop Switch $iFlag Case 0 If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf Case 1 If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf EndIf Case 2 If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then $sHold &= $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= $aFSplit[$iCC] & Chr(1) EndIf EndIf EndSwitch Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc Link to comment Share on other sites More sharing options...
Inverted Posted June 7, 2009 Share Posted June 7, 2009 (edited) Can you pz check the lines : If $diff[0][0] = 0 AND $new[0][0] = 0 AND $old[0][0] = 0 Then MsgBox(64,"","I file presenti nella cartella di destinazione sono già aggiornati.") It's missing an EndIf I believe. Edited June 7, 2009 by Inverted Link to comment Share on other sites More sharing options...
Metal Posted June 7, 2009 Author Share Posted June 7, 2009 You're right, man! I feel so stupid >.< Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now