SparkSoft Posted October 10, 2010 Posted October 10, 2010 (edited) Im having difficulty undertsanding arrays. Heres what I wanted to do: choose a folder then put list of files and folders list into an array, then choose another folder then copy files from the list, one by one , into that folder so that the script doesnt crash <br>Heres my code: #include <file.au3> #include <array.au3> ;Variables Global $ChosenDirectory = FileSelectFolder("File To Backup","C:/") Global $FilesBackupList = File If @Error = 1 Then MsgBox(0,"Error","No Files Found!") Exit EndIf If @error = 4 Then MsgBox(0,"Error","No Files In Folder") Exit EndIf _ArrayDisplay($FilesBackupList,"$FilesBackupList") $FolderToBackupTo = FileSelectFolder("Select FOlder To Backup to","C:/") FileCopy($FilesBackupList,$FolderToBackupTo) </array.au3></file.au3> Edited October 10, 2010 by SparkSoft [center]First Ever Script/App[/center][center]Simple Battery Meter[/center]
jaberwacky Posted October 10, 2010 Posted October 10, 2010 Global $ChosenDirectory = FileSelectFolder("File To Backup", "C:/") Global $FolderToBackupTo = FileSelectFolder("Select Folder To Backup to", "C:/") FileCopy($ChosenDirectory, $FolderToBackupTo) Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
SparkSoft Posted October 10, 2010 Author Posted October 10, 2010 I need to put the files chosen into a list then copy each file individually from that list to a folder im new [center]First Ever Script/App[/center][center]Simple Battery Meter[/center]
Kalin Posted October 10, 2010 Posted October 10, 2010 You should read some of the distributed AutoIt resources. Like guides, tutorials, open source reviewing, etc. Best way to learn AutoIt.
SparkSoft Posted October 10, 2010 Author Posted October 10, 2010 Ive read quite a few guides but I cant understand how to do this [center]First Ever Script/App[/center][center]Simple Battery Meter[/center]
Kalin Posted October 10, 2010 Posted October 10, 2010 (edited) For starters, When you put If @error = 4 it isn't necessary. You can use If @error Then <statements> On all times you've used the @error macro. *edit* I don't think you should be declaring the variables globally for the code you're using. You can do this instead $ChosenDirectory = FileSelectFolder("File To Backup","C:/") $FilesBackupList = ; Whatever value you're setting to this variable here don't include this character ";" Edited October 10, 2010 by Kalin
jaberwacky Posted October 10, 2010 Posted October 10, 2010 (edited) This worked on my machine... #include <File.au3> #include <Array.au3> Global $ChosenDirectory = FileSelectFolder("File To Backup", "C:/") Global $FilesBackupList = _FileListToArray($ChosenDirectory) If @error = 1 Then MsgBox(0, "Error", "No Files Found!") Exit EndIf If @error = 4 Then MsgBox(0, "Error", "No Files In Folder") Exit EndIf _ArrayDisplay($FilesBackupList, "$FilesBackupList") $FolderToBackupTo = FileSelectFolder("Select FOlder To Backup to", "C:/") ; check for errors with this variable Global $CheckForError ; some file attributes may make the filemove impossible For $i = 1 To $FilesBackupList $CheckForError = FileCopy($FilesBackupList[$i], $FolderToBackupTo) If $CheckForError = 0 Then MsgBox(48, "Error", "File Wasn't copied") EndIf Next Edited October 10, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Kalin Posted October 10, 2010 Posted October 10, 2010 This worked on my machine... #include <File.au3> #include <Array.au3> Global $ChosenDirectory = FileSelectFolder("File To Backup", "C:/") Global $FilesBackupList = _FileListToArray($ChosenDirectory) If @error = 1 Then MsgBox(0, "Error", "No Files Found!") Exit EndIf If @error = 4 Then MsgBox(0, "Error", "No Files In Folder") Exit EndIf _ArrayDisplay($FilesBackupList, "$FilesBackupList") $FolderToBackupTo = FileSelectFolder("Select FOlder To Backup to", "C:/") Global $CheckForError For $i = 1 To $FilesBackupList $CheckForError = FileCopy($FilesBackupList[$i], $FolderToBackupTo) If $CheckForError = 0 Then MsgBox(48, "Error", "File Wasn't copied") EndIf Next Same.. I don't understand what he means by it's not working.
jaberwacky Posted October 10, 2010 Posted October 10, 2010 FileCopy won't copy all files if certain file attributes are set. I've run into this before but I'd have to do some digging which I'm far too sleepy to feel like doing... Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
SparkSoft Posted October 10, 2010 Author Posted October 10, 2010 Ok thanks but you see what im trying to do though dont you [center]First Ever Script/App[/center][center]Simple Battery Meter[/center]
GEOSoft Posted October 10, 2010 Posted October 10, 2010 (edited) #include<file.au3> #include<array.au3> Global $sFldr, $sbakFldr, $aFiles $sFldr = FileSelectFolder("Folder containing files to backup", "C:\", 2) & "\" If NOT @Error Then $sBakFldr = FileSelectFolder("Select backup Folder", "C:\", 7) & "\" If @Error Then Exit $aFiles = _FileListToArray($sFldr, "*", 1) For $i = 1 To UBound($aFiles) -1 If NOT FileCopy($sFldr & $aFiles[$i], $sBakFldr & $aFiles[$i], 1) Then MsgBox(4096, "Error", "Unable to copy file" & @CRLF & $aFile[$i]) ContinueLoop EndIf Next MsgBox(4096, "Finished", "file copying has been completed") Edited October 10, 2010 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!"
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