argv1 Posted November 28, 2009 Posted November 28, 2009 Hi, I would like to get the DriveLetter of my USB Stick called Linda. So the only way I know is to list all devices with DriveGetDrives and then check if one of the fetched drives got the name Linda. Is there an easier way to do this? Or did anybody got a piece of code for me, plz. :-)
GEOSoft Posted November 29, 2009 Posted November 29, 2009 It will help to narrow the drive search down to the proper type. $aDrives = DriveGetDrive("Removable") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = "Linda" Then MsgBox(0, "Result", DriveGetLabel($aDrives[$i]) & " is drive " & StringUpper($aDrives[$i])) EndIf Next George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
argv1 Posted November 29, 2009 Author Posted November 29, 2009 (edited) hi and thx, I tried to use this in a function to also find not removable drives, but recieving 3 error msg Func FindingDriveLetter($x) { $aDrives = DriveGetDrive("ALL") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = $x Then return $aDrives[$i] EndIf Next } Dim $DriveLetter1 = FindingDriveLetter(Linda) Dim $DriveLetter2 = FindingDriveLetter(Paul) D:\backup.au3(3,28) : ERROR: syntax error (illegal character) Func FindingDriveLetter($x) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\backup.au3(5,31) : WARNING: $aDrives: possibly used before declaration. For $i = 1 To UBound($aDrives) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\backup.au3(10,1) : ERROR: syntax error (illegal character) } ^ D:\backup.au3(5,31) : ERROR: $aDrives: undeclared global variable. For $i = 1 To UBound($aDrives) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\backup.au3 - 3 error(s), 1 warning(s) Is it important to write the function first? I saw examples where the functions are at the end of the script, but if I do this I recieve even more error msgs Edited November 29, 2009 by argv1
argv1 Posted November 29, 2009 Author Posted November 29, 2009 oh wait i found an error, plz ignor this post
GEOSoft Posted November 29, 2009 Posted November 29, 2009 oh wait i found an error, plz ignor this post Just one error? That whole piece of code looks like the result of a multi-vehicle accident. You are mixing syntax from two differnt languages resulting in 3 errors and a warning. Func FindingDriveLetter($x) Local $aDrives = DriveGetDrive("ALL") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = $x Then return $aDrives[$i] EndIf Next EndFunc Global $DriveLetter1 = FindingDriveLetter(Linda) Global $DriveLetter2 = FindingDriveLetter(Paul) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
argv1 Posted November 29, 2009 Author Posted November 29, 2009 (edited) yes thanks I saw that I used {} instead of EndFunc but right now I just finished my first little autoit script expandcollapse popup;Backup Script 29.11.09 Dim $BackupErfolgreich = Backuppen() If ($BackupErfolgreich) Then AlteBackupsLoeschen() MsgBox (0, "Statusfenster", "Backup erstellt, altes Backup gelöscht") Else MsgBox (0, "Statusfenster", "Backup war nicht möglich") EndIf Func Backuppen() Dim $BackupFileName = @YEAR & '-' & @MON & '-' & @MDAY Dim $DriveLetter = DriveLetterFinden('Linda') Dim $DriveLetter2 = DriveLetterFinden('mitalles') Local $Ordnerliste[4] $Ordnerliste[0]= 'keep' $Ordnerliste[1]= 'web' $Ordnerliste[2]= 'Bilder' $Ordnerliste[3]= 'privat' Dim $sWinRAR = @ProgramFilesDir & '\winrar\' For $counter = 0 to 1 RunWait($sWinRAR & 'winrar a "C:\Backup\"' & $BackupFileName & '-Stick-' & $Ordnerliste[$counter] & ' ' & $DriveLetter & '\' & $Ordnerliste[$counter] ) Next For $counter = 2 to 3 RunWait($sWinRAR & 'winrar a "C:\Backup\"' & $BackupFileName & '-' & $Ordnerliste[$counter] & ' ' & $DriveLetter2 & '\' & $Ordnerliste[$counter] ) Next If @error Then return False Else return True EndIf EndFunc Func DriveLetterFinden($x) $aDrives = DriveGetDrive("ALL") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = $x Then return $aDrives[$i] EndIf Next EndFunc Func AlteBackupsLoeschen() Local $Search = FileFindFirstFile("C:\Backup\*.*") Local $File While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop If Not StringInStr( $File, @YEAR & '-' & @MON & '-' & @MDAY) Then FileDelete("C:\Backup\" & $File) EndIf WEnd EndFunc ... and it works. I'm proud and happy. Edited November 29, 2009 by argv1
GEOSoft Posted November 29, 2009 Posted November 29, 2009 Well done and welcome to the forums. One tip though. Don't use Dim, There has been a lot of opposition to Dim and it may well become redundant in the future. If the variable is only used within a function then make it Local, if the variable must be accessed from multiple functions ddeclare it as Global. Also if you are using the Beta we now have Static as well. By the way, Dim was originally in there to declare the Dim(ension) of an array and most of the opposition has come from the fact that people use it to declare non-arrays or empty arrays which is deemed to be sloppy coding. Yes, you still find it in VBS and a few others but that doesn't make it correct, just old. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
argv1 Posted November 29, 2009 Author Posted November 29, 2009 (edited) thanks a lot for the tipps with dim but currently I got a little challenge, I tried to optimize the script to this: expandcollapse popup;Backup Script 29.11.09 Dim $BackupErfolgreich = Backuppen() If ($BackupErfolgreich) Then MsgBox (0, "Statusfenster", "Backup erstellt, altes Backup gelöscht") Else MsgBox (0, "Statusfenster", "Backup war nicht möglich") EndIf Func Backuppen() Local $BackupFileName = @YEAR & '-' & @MON & '-' & @MDAY Local $DriveLetter = DriveLetterFinden('Linda') Local $DriveLetter2 = DriveLetterFinden('mitalles') Local $Ordnerliste[4] $Ordnerliste[0]= 'keep' $Ordnerliste[1]= 'web' $Ordnerliste[2]= 'Bilder' $Ordnerliste[3]= 'privat' Local $sWinRAR = @ProgramFilesDir & '\winrar\' For $counter = 0 to 1 If Not (HeuteSchonGebackuped($Ordnerliste[$counter])) Then RunWait($sWinRAR & 'winrar a "C:\Backup\"' & $BackupFileName & '-Stick-' & $Ordnerliste[$counter] & ' ' & $DriveLetter & '\' & $Ordnerliste[$counter] ) AlteBackupsLoeschen($Ordnerliste[$counter]) Else MsgBox (0, "Statusfenster", "Heute wurde bereits ein Backup von " & $Ordnerliste[$counter] & " erstellt") EndIf Next For $counter = 2 to 3 If Not (HeuteSchonGebackuped($Ordnerliste[$counter])) Then RunWait($sWinRAR & 'winrar a "C:\Backup\"' & $BackupFileName & '-' & $Ordnerliste[$counter] & ' ' & $DriveLetter2 & '\' & $Ordnerliste[$counter] ) AlteBackupsLoeschen($Ordnerliste[$counter]) Else MsgBox (0, "Statusfenster", "Heute wurde bereits ein Backup von " & $Ordnerliste[$counter] & " erstellt") EndIf Next If @error Then return False Else return True EndIf EndFunc Func DriveLetterFinden($x) Local $aDrives = DriveGetDrive("ALL") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = $x Then return $aDrives[$i] EndIf Next EndFunc Func AlteBackupsLoeschen($ZuLoeschen) Local $Search = FileFindFirstFile("C:\Backup\*.*") Local $File While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop If Not StringInStr( $File, @YEAR & '-' & @MON & '-' & @MDAY) Then If StringInStr( $File, $ZuLoeschen) Then FileDelete("C:\Backup\" & $File) EndIf EndIf WEnd EndFunc Func HeuteSchonGebackuped($ZuPruefen) Local $Search = FileFindFirstFile("C:\Backup\*.*") Local $File While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop If StringInStr( $File, @YEAR & '-' & @MON & '-' & @MDAY) Then If StringInStr( $File, $ZuPruefen) Then return True Else return False EndIf EndIf WEnd EndFunc but the script will create new Backups of privat, keep and web even if the folder exists. Just for bilder it tells me that this file already exists, if it exist. what do I oversee here? I hope it is ok not to open a new thread for this Edited November 29, 2009 by argv1
GEOSoft Posted November 29, 2009 Posted November 29, 2009 (edited) For openers I would forget using WinRAR to do it. WinRAR is based on 7zip.Download the commandline version of 7zip and all the switches you need to do what you want are in there. I have a customized version of the 7Zip help file (Everything except Commandline related material is stripped) if you need it.EDIT: Speelink error Edited November 29, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
argv1 Posted November 29, 2009 Author Posted November 29, 2009 (edited) Ok a donwloaded 7a and change the script to this: expandcollapse popup;Backup Script 29.11.09 Dim $BackupErfolgreich = Backuppen() If ($BackupErfolgreich) Then MsgBox (0, "Statusfenster", "Backup erstellt, altes Backup gelöscht") Else MsgBox (0, "Statusfenster", "Backup war nicht möglich") EndIf Func Backuppen() Local $BackupFileDate = @YEAR & '-' & @MON & '-' & @MDAY Local $DriveLetter1 = DriveLetterFinden('Linda') Local $DriveLetter2 = DriveLetterFinden('mitalles') Local $Ordnerliste[4] $Ordnerliste[0]= 'keep' $Ordnerliste[1]= 'web' $Ordnerliste[2]= 'Bilder' $Ordnerliste[3]= 'privat' Local $s7za = @ProgramFilesDir & '\7za\' For $counter = 0 to 1 If Not (HeuteSchonGebackuped($Ordnerliste[$counter])) Then RunWait($s7za & '7za.exe a "C:\Backup\"' & $BackupFileDate & '-Stick-' & $Ordnerliste[$counter] & ' ' & $DriveLetter1 & '\' & $Ordnerliste[$counter] ) AlteBackupsLoeschen($Ordnerliste[$counter]) Else MsgBox (0, "Statusfenster", "Heute wurde bereits ein Backup von " & $Ordnerliste[$counter] & " erstellt") EndIf Next For $counter = 2 to 3 If Not (HeuteSchonGebackuped($Ordnerliste[$counter])) Then RunWait($s7za & '7za.exe a "C:\Backup\"' & $BackupFileDate & '-' & $Ordnerliste[$counter] & ' ' & $DriveLetter2 & '\' & $Ordnerliste[$counter] ) AlteBackupsLoeschen($Ordnerliste[$counter]) Else MsgBox (0, "Statusfenster", "Heute wurde bereits ein Backup von " & $Ordnerliste[$counter] & " erstellt") EndIf Next If @error Then return False Else return True EndIf EndFunc Func DriveLetterFinden($x) Local $aDrives = DriveGetDrive("ALL") For $i = 1 To UBound($aDrives) -1 If DriveGetLabel($aDrives[$i]) = $x Then return $aDrives[$i] EndIf Next EndFunc Func AlteBackupsLoeschen($ZuLoeschen) Local $Search = FileFindFirstFile("C:\Backup\*.*") Local $File While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop If Not StringInStr( $File, @YEAR & '-' & @MON & '-' & @MDAY) Then If StringInStr( $File, $ZuLoeschen) Then FileDelete("C:\Backup\" & $File) EndIf EndIf WEnd EndFunc Func HeuteSchonGebackuped($ZuPruefen) Local $Search = FileFindFirstFile("C:\Backup\*.*") Local $File While 1 If $Search = -1 Then ExitLoop EndIf $File = FileFindNextFile($Search) If @error Then ExitLoop If StringInStr( $File, @YEAR & '-' & @MON & '-' & @MDAY) Then If StringInStr( $File, $ZuPruefen) Then return True Else return False EndIf EndIf WEnd EndFunc I'll still recieve the msg that a backup for the folder Bilder already exists (Heute wurde bereits ein Backup von Bilder erstellt) what is right, but for the other 3 the program create new backups. Why, if they even exists? could the filesize be the problem? The Backup of Bilder is 1,78 GB, the other files are between 10 and 450 MB Is there a possibility to run 7za as a proccess in the background? Edited November 29, 2009 by argv1
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