Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Directory Listing in NSIS (http://forums.winamp.com/showthread.php?t=175873)

dasein 8th April 2004 19:42

Directory Listing in NSIS
 
Hello,

Is there a way to get a directory listing into a variable? There is a random directory generated by Thunderbird's createprofile option that I need to install some files into.

I've tried to use this line:
nsExec::Exec 'dir "$APPDATA\Thunderbird\Profiles\default"'
but this gives me "error" in the stack.

Is there some easier way to do this?

Thanks!

Joost Verburg 8th April 2004 20:13

To enumerate directories you have to use FindFirst, FindNext and FindClose.

dasein 8th April 2004 20:42

Ah... Thank you very much. I didn't know the Find commands included directories and not just files.

Thanks again.

Brummelchen 26th June 2006 03:10

very old question, i needed that hint, here the result
PHP Code:

Function findfile0
  Delete 
"$EXEDIR\\foldlist.ini"
  
Delete "$EXEDIR\\filelist.ini"
  
StrCpy $R7 "1"
  
StrCpy $R8 "0"
  
StrCpy $R9 "0"
  
StrCpy $SEARCHDIR $EXEDIR ; <-- modify directory (from input or fixed)
  
Push $SEARCHDIR
  Call findfile2
  Call findfile1
FunctionEnd


Function findfile1
findfile1_loop
:
  
ReadINIStr $"$EXEDIR\\foldlist.ini" subdirs $R7
  StrCmp 
$"" findfile1_done
    Push 
$3
    Call findfile2
    IntOp $R7 $R7 
1
    IntCmp $R7 $R8 0 0 findfile1_done
  
Goto findfile1_loop
findfile1_done
:
FunctionEnd


Function findfile2
Pop 
$2
FindFirst 
$$"$2\\*.*"
findfile2_loop:
  
StrCmp $"" findfile2_done
  StrCmp 
$"." findfile2_loop02
  StrCmp 
$".." findfile2_loop02
  IfFileExists 
"$2\\$1\\*.*" 0 findfile2_loop01
    Call subdir
    
Goto findfile2_loop02
  findfile2_loop01
:
  
Call filewrite
  findfile2_loop02
:
  
FindNext $$1
  
Goto findfile2_loop
findfile2_done
:
FunctionEnd


Function subdir
  IntOp $R8 $R8 
1
  WriteINIStr 
"$EXEDIR\\foldlist.ini" subdirs $R8 $2\\$1
FunctionEnd

Function filewrite
  IntOp $R9 $R9 
1
  WriteINIStr 
"$EXEDIR\\filelist.ini" filelist $R9 $2\\$1
FunctionEnd 

The idea behind:
- search starting folder and grab all files (filelist.ini)
- write subfolders into foldlist.ini
- then readout foldlist.ini and grab files and folders again

$R9 is filelist-pointer
$R8 is folderlist-pointer
$R7 is helper-pointer

$R8 raises and when $R7 > $R8 (or $3 is empty) the end of the folder list was reached.

modify function "filewrite" as you wish (other output format eg.)

HTH


All times are GMT. The time now is 05:48.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.