Jump to content

Puzzled by Arrays - FileCopy function not working properly


skysel
 Share

Go to solution Solved by BrewManNH,

Recommended Posts

So I'm using _RecFileListToArray by Melba23, I've added _ArrayDisplay to the function, to make sure values returned are normal - which they are.

$DIR is the directory where the script is searching for files / folders.

What bugs me, is, that when I preform FileCopy operation (according to array that would be - c:1filename.tif -> c:1filenamefilename.tif) but it only copies file from row 1 in the array! other folders are left blank :-(

I can't seem to find the error below... help appreciated!

Func KopirajDatoteke()

    $FileArray = _RecFileListToArray($DIR, "*", 1, 0, 0, 2)
    _ArrayDelete($FileArray,0)

    $FolderArray = _RecFileListToArray($DIR, "*", 2, 0, 1, 2)
    _ArrayDelete($FolderArray,0)

    For $i = 1 To $FileArray[0]
        Next
    For $i = 1 To $FolderArray[0]
        Next

FileCopy($FileArray[$i],$FolderArray[$i],8)
_ArrayDisplay($FileArray)
_ArrayDisplay($FolderArray)
EndFunc
Link to comment
Share on other sites

Your copy operation needs to be inside one of those loops I believe.

Cannot be certain because, you do not explain the structure of your folders of what it is you're trying to achieve.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The array elements returned by that function do not have the path added to the file names, so you wouldn't be copying the correct files anyways.

So it would be returning <filename> without the path $DIR before it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The array elements returned by that function do not have the path added to the file names, so you wouldn't be copying the correct files anyways.

So it would be returning <filename> without the path $DIR before it.

Hi there,

_ArrayDisplay shows me FULL path to files and FULL path to folders, so I think that's not what's wrong (I have tried various combinations on parameters for _RecFileListToArray, can't remember now if I've set it back or not here on OP)..

What I'm trying to achieve is to get list of all files and folders in 1 folder (e.g. c:1) and copy them accordingly to subfolders.

Folders are named by filenames, for which I use another function and it works well.

For example, the structure looks like this:

Folders:

c:100000001

c:100000002

c:100000003

c:100000004

Files:

c:100000001.tif

c:100000002.tif

c:100000003.tif

c:100000004.tif

Desired FileCopy operation should copy files to those folders, I have both sorted with parameter within _RecFileListToArray, so it would always match since both are same name:

c:10000000100000001.tif

c:10000000100000002.tif

c:10000000100000003.tif

c:10000000100000004.tif

I have also tried to put the FileCopy operation in the second loop, right before Next statement, however files are still not copied.

I hope I made it bit clearer now on my desired output ;-)

Link to comment
Share on other sites

Try that.

Func KopirajDatoteke()

    $FileArray = _RecFileListToArray($DIR, "*", 1, 0, 0, 2)
    _ArrayDelete($FileArray, 0)

    $FolderArray = _RecFileListToArray($DIR, "*", 2, 0, 1, 2)
    _ArrayDelete($FolderArray, 0)


    For $i = 1 To $FolderArray[0]
        For $i2 = 1 To $FileArray[0]
            FileCopy($FileArray[$i2], $FolderArray[$i], 8)
        Next
    Next


    _ArrayDisplay($FileArray)
    _ArrayDisplay($FolderArray)
EndFunc   ;==>KopirajDatoteke
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I think I figured out what is going on. You're deleting the $FileArray and $FolderArray count in the first element, so your for loops have no end, so they're ignored.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

Try that.

Func KopirajDatoteke()

    $FileArray = _RecFileListToArray($DIR, "*", 1, 0, 0, 2)
    _ArrayDelete($FileArray, 0)

    $FolderArray = _RecFileListToArray($DIR, "*", 2, 0, 1, 2)
    _ArrayDelete($FolderArray, 0)


    For $i = 1 To $FolderArray[0]
        For $i2 = 1 To $FileArray[0]
            FileCopy($FileArray[$i2], $FolderArray[$i], 8)
        Next
    Next


    _ArrayDisplay($FileArray)
    _ArrayDisplay($FolderArray)
EndFunc   ;==>KopirajDatoteke

 

I have tried changing $i to $j as you provided with $i2 and it didn't work.

Edit: Ah I see you've placed Next statements differently - I will try and tell how it goes :-)

I think I figured out what is going on. You're deleting the $FileArray and $FolderArray count in the first element, so your for loops have no end, so they're ignored.

 

I am only deleting the first row, since it includes count of files and thats interfering with my actions (since I don't have a folder named e.g. 9 (9 files in folder) and file 9.tif does not exist, obviously) :-)

What is your purposed solution? I am still trying to wrap my head around loops...

Thank you both for your effort so far!

Edited by skysel
Link to comment
Share on other sites

  • Solution

Leave the file and folder counts in the array, don't use _ArrayDelete to delete it. Then your For loops will actually do something.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

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