Sign in to follow this  
Followers 0
SparkSoft

FileList to array

11 posts in this topic

#1 ·  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]

Share this post


Link to post
Share on other sites



Global $ChosenDirectory = FileSelectFolder("File To Backup", "C:/")

Global $FolderToBackupTo = FileSelectFolder("Select Folder To Backup to", "C:/")

FileCopy($ChosenDirectory, $FolderToBackupTo)

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

You should read some of the distributed AutoIt resources.

Like guides, tutorials, open source reviewing, etc.

Best way to learn AutoIt.

;)

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

#6 ·  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

Share this post


Link to post
Share on other sites

#7 ·  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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Ok thanks but you see what im trying to do though dont you


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

Share this post


Link to post
Share on other sites

#11 ·  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!"

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0