Old 10th November 2009, 20:56   #1
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Exclamation Folder list into an array

I'm looking to find a list of folders and insert each folder into an array. Has anyone done something similar?

Ultimately, I want to populate a dropbox with the array contents and use the selection to kick off an installer in that folder.

So, if I have folders 1.0.0.1, 1.0.0.2, 1.0.0.3, and 1.0.0.5, I would need array index 0 to hold 1.0.0.1, array index 1 to hold 1.0.0.2, etc.

Thank you!
todd_ingr is offline   Reply With Quote
Old 12th November 2009, 10:21   #2
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
Are you aware that NSIS has no native support for arrays ? (except http://nsis.sourceforge.net/Arrays_in_NSIS )

What system do you want to use to display & populate the dropbox ?
Wizou is offline   Reply With Quote
Old 12th November 2009, 14:54   #3
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Quote:
Originally posted by Wizou
Are you aware that NSIS has no native support for arrays ? (except http://nsis.sourceforge.net/Arrays_in_NSIS )

What system do you want to use to display & populate the dropbox ?
Yes, I'm aware of Afrow UK's work. It's great.

I'm thinking of writing the array to the ListItems property of the combobox defined in an INI.
todd_ingr is offline   Reply With Quote
Old 12th November 2009, 15:01   #4
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
check the help file on FindFirst to enumerate the files or folder, you can fill your array like this

then you can use ${myArray->Concat} with separator char '|', as expected by ListItems
Wizou is offline   Reply With Quote
Old 12th November 2009, 20:59   #5
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Quote:
Originally posted by Wizou
check the help file on FindFirst to enumerate the files or folder, you can fill your array like this

then you can use ${myArray->Concat} with separator char '|', as expected by ListItems
Do you think that would be easier than writing the list of folders to a text file and doing reads on it?
todd_ingr is offline   Reply With Quote
Old 12th November 2009, 22:04   #6
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Okay, I've put together this little function to get a list of the directories into an array. Unfortunately, my array contains the typical . and .. present when you do a dir command in DOS.

Any ideas how to exclude . and ..?

code:
Function CreateDirList

${dirList->Init}

Var /global ArrayIndex

StrCpy $ArrayIndex 0

FindFirst $0 $1 $DRIVE_LETTER:\*.*
loop:
StrCmp $1 "" done
${dirList->Write} $ArrayIndex "$1"
FindNext $0 $1
IntOp $ArrayIndex $ArrayIndex + 1
Goto loop
done:
${dirList->Debug}
FindClose $0

todd_ingr is offline   Reply With Quote
Old 13th November 2009, 09:00   #7
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
code:

StrCmp $1 "." skip
StrCmp $1 ".." skip
${dirList->Write} $ArrayIndex "$1"
skip:
FindNext $0 $1

Wizou is offline   Reply With Quote
Old 13th November 2009, 15:36   #8
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Quote:
Originally posted by Wizou
code:

StrCmp $1 "." skip
StrCmp $1 ".." skip
${dirList->Write} $ArrayIndex "$1"
skip:
FindNext $0 $1

Hadn't thought of it that way. Thanks, Wizou.

Here's my code, if anyone else finds it useful.

code:
Function CreateDirList

${dirList->Init}

Var /global ArrayIndex

StrCpy $ArrayIndex 0

FindFirst $0 $1 $DRIVE_LETTER:\*.*
loop:
StrCmp $1 "" done
StrCmp $1 "." skip
StrCmp $1 ".." skip
IfFileExists "$DRIVE_LETTER:\$1\*.*" IsDir skip
IsDir:
${dirList->Write} $ArrayIndex "$1"
IntOp $ArrayIndex $ArrayIndex + 1
skip:
FindNext $0 $1
Goto loop
done:
${dirList->Reverse} ; -- Reverse the list so that the order is descending
${dirList->Concat} $PickVerList "|"
FindClose $0

FunctionEnd

todd_ingr is offline   Reply With Quote
Old 13th November 2009, 15:47   #9
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
you can also use GetFileAttributes to check that a file is really a folder
Wizou is offline   Reply With Quote
Old 13th November 2009, 17:01   #10
todd_ingr
Junior Member
 
Join Date: Jan 2006
Posts: 21
Quote:
Originally posted by Wizou
you can also use GetFileAttributes to check that a file is really a folder
I tried, but my $R0 variable is always blank.

code:
${GetFileAttributes} "$1" "ALL" $R0
MessageBox MB_OK "Directory: $1 :: Attribute: $R0"



That message box shows the folder name, but the attribute is always empty, except for '.' and '..'. Those show DIRECTORY attribute.
todd_ingr is offline   Reply With Quote
Old 13th November 2009, 17:20   #11
Wizou
Senior Member
 
Join Date: Aug 2007
Location: Paris, France
Posts: 304
Mmmmh... try to use a fully qualified path like
code:
${GetFileAttributes} "$DRIVE_LETTER:\$1" "DIRECTORY" $R0


some NSIS functions (and Windows API) requires fully qualified path rather than relative path or file name
Wizou is offline   Reply With Quote
Old 13th November 2009, 22:39   #12
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
I don't know GetFileAttributes, but I would expect the first parameter to be the output, not the input. That's how all NSIS functions are done, so that's how all macros should be coded as well.
MSG is offline   Reply With Quote
Old 13th November 2009, 23:42   #13
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 571
${GetFileAttributes} is documented in the NSIS Users Manual:

http://nsis.sourceforge.net/Docs/AppendixE.html#E.1.7

The output is the last parameter, e.g.
code:
${GetFileAttributes} "C:\MSDOS.SYS" "ALL" $R0
; $R0=READONLY|HIDDEN|SYSTEM|ARCHIVE

pengyou is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump