- NSIS Discussion
- Folder list into an array
Archive: Folder list into an array
todd_ingr
10th November 2009 20:56 UTC
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!
Wizou
12th November 2009 10:21 UTC
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 ?
todd_ingr
12th November 2009 14:54 UTC
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.
Wizou
12th November 2009 15:01 UTC
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
todd_ingr
12th November 2009 20:59 UTC
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
12th November 2009 22:04 UTC
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 ..?
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
Wizou
13th November 2009 09:00 UTC
StrCmp $1 "." skip
StrCmp $1 ".." skip
${dirList->Write} $ArrayIndex "$1"
skip:
FindNext $0 $1
todd_ingr
13th November 2009 15:36 UTC
Originally posted by Wizou
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.
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
Wizou
13th November 2009 15:47 UTC
you can also use GetFileAttributes to check that a file is really a folder
todd_ingr
13th November 2009 17:01 UTC
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.
${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.
Wizou
13th November 2009 17:20 UTC
Mmmmh... try to use a fully qualified path like
${GetFileAttributes} "$DRIVE_LETTER:\$1" "DIRECTORY" $R0
some NSIS functions (and Windows API) requires fully qualified path rather than relative path or file name
MSG
13th November 2009 22:39 UTC
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.
pengyou
13th November 2009 23:42 UTC
${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.
${GetFileAttributes} "C:\MSDOS.SYS" "ALL" $R0
; $R0=READONLY|HIDDEN|SYSTEM|ARCHIVE