Jump to content

FileExist with array


JohnSte
 Share

Go to solution Solved by JLogan3o13,

Recommended Posts

Greetings,

Thanks to some very helpful previous advice I have made some headway with my script. But I'm either missing something obvious (likely) or not coding the script correctly (also likely). When I compile and run this, I get an error "Line 2789, Error: Error parsing function call."

The script:

#include <Array.au3>

#include <File.au3>

#include <MsgBoxConstants.au3>

$FileListArray = _FileListToArray ("C:Windows")

$FileListTArray= _FileListToArray ("C:Test")

For $FileList in $FileListArray;

If Not FileExist($FileList) in $FileListTArray Then

DirCreate($FileList) in $FileListTArray)

EndIf

Next

Basically all I want to do is check if each file (directory) in the first directory exists in the second, and if not, create it, running through the list of files (directories) in the first array.

Any help greatly appreciated!

Link to comment
Share on other sites

  • Moderators
  • Solution

Start with removing the in $FileListTArray) from the end of your DirCreate line..

Actually, looking at the code more closely, there are more issues.. Correct me if I am wrong, but you're wanting to create an array of all files in C:Windows, and then if that directory does not exist in C:Test create it? Maybe something more like this.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

$aList = _FileListToArray("C:\WIndows", Default, $FLTA_FOLDERS)
$anewList = _FileListToArray(@DesktopDir & "\Test", Default, $FLTA_FOLDERS)

    For $dir In $aList
        For $newDir In $anewList
            If Not FileExists($dir) Then DirCreate(@DesktopDir & "\Test\" & $dir)
        Next
    Next
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks, JohnOne - I was wondering why it's running and I'm not seeing any results :*

Is there a way to get it to look at the directory from elsewhere, as opposed to needing to be in the path?

and I need the $iflag option with FLTA_FOLDERS to exclude the files, it appears.

Link to comment
Share on other sites

  • Moderators

You are quite correct, J1, I should have been less liberal with copying and pasting the OP's code. Fixed my post above

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

JohnSte, what do you mean "look at the path from elsewhere". Are you meaning reading your path from a variable, or an external source like a file?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

You can run the script from anywhere, so long as you have the paths coded. I ran my example from my Desktop and it worked just fine.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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