Jump to content

is this a _filelisttoarray bug or do I misunderstand it


speedi
 Share

Recommended Posts

I have a problem, but it seems to have been caused by a bug in _filelisttoarray or I bady misunderstand it.

I thought I could use _filelisttoarray and then filecopy to copy from a source folder, all files, folders and files within those folders to another location, but that does not work... Someone please try this and tell me the result or tell me what I am doing wrong!!! Did the folders copy correctly? Can you view their contents with windows explorer? Mine end up as a file not a folder. Thanks!

the script follows:

#include <File.au3>

#Include <Array.au3>

; srcfolder can be any folder that has sub folders that have files

; desfolder can be any test or temporary folder you create

$srcFolder = @MyDocumentsDir ; Folder you wish to copy

$desFolder = "c:\testdir" ; Folder you wish to move files to

$aFiles = _FileListToArray($srcFolder)

; the count can be whatever it takes to get at least one sub folder and files copied

For $i = 1 To 200

filecopy($srcFolder & '\' & $aFiles[$i], $desFolder & '\' & $aFiles[$i], 9)

Next

Edited by speedi
Link to comment
Share on other sites

The problem you are running into is probably the FileCopy() That won't work on folders so you have to put a conditional in there

$sSrc = $srcFolder & "\" & $aFiles[$i]
If StringInStr(FileGetAttrib($sSrc), "D") Then
   DirCopy($sSrc, $desFolder & '\' & $aFiles[$i])
Else
   FileCopy($sSrc, $desFolder & '\' & $aFiles[$i], 9)
EndIf

Also, when posting code, please highlite your code (select it by draging the mouse over it) and click the editor toolbar icon that looks like <>. That makes it much easier to read

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

Link to comment
Share on other sites

The problem you are running into is probably the FileCopy() That won't work on folders so you have to put a conditional in there

$sSrc = $srcFolder & "\" & $aFiles[$i]
If StringInStr(FileGetAttrib($sSrc), "D") Then
   DirCopy($sSrc, $desFolder & '\' & $aFiles[$i])
Else
   FileCopy($sSrc, $desFolder & '\' & $aFiles[$i], 9)
EndIf

Also, when posting code, please highlite your code (select it by draging the mouse over it) and click the editor toolbar icon that looks like <>. That makes it much easier to read

Mr Nice Guy, You are the man... Your correction worked perfectly... Thank you... Now if I could get an answer to my other post about changing the file type so I can recover some files (just a few recent ones)... Thanks again and also for the tip on listing a script...
Link to comment
Share on other sites

Instead of defining counting from 1 to 200, you only want to run the loop for as many times as you have files.

For $i = 1 to Ubound($aFiles) -1

James

the count was just to make the testing faster since there were a whole lot more files and folder... Edited by speedi
Link to comment
Share on other sites

Mr Nice Guy, You are the man... Your correction worked perfectly... Thank you... Now if I could get an answer to my other post about changing the file type so I can recover some files (just a few recent ones)... Thanks again and also for the tip on listing a script...

happy to hear it worked

What other post are you refering to? Please, don't make me hunt you down.

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

Link to comment
Share on other sites

OP, if you are looking for a way to change the properties from file to folder to recover files inside (as it sounds like that may have been what you think happened?)

I just recently had something like this happen as well, However, what happened was a file being copied was renamed to the folder name and with the overwrite flag used, the file copied over the folder.

The folder does not actually exist anymore and I bet if you add "." and the extension of the file, you will be able to use the file as it should. (I found this out because all the files I was moving were pdfs so when I added .pdf the the end of the folder name, adobe opened up and showed me the document file that had been renamed)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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...