Jump to content

Recommended Posts

Posted (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 by SparkSoft

[center]First Ever Script/App[/center][center]Simple Battery Meter[/center]

Posted

You should read some of the distributed AutoIt resources.

Like guides, tutorials, open source reviewing, etc.

Best way to learn AutoIt.

;)

Posted (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 by Kalin
Posted (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 by jaberwocky6669
Posted

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.

Posted (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 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!"

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...