Old 8th April 2004, 19:42   #1
dasein
Junior Member
 
Join Date: Apr 2004
Posts: 2
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!
dasein is offline   Reply With Quote
Old 8th April 2004, 20:13   #2
Joost Verburg
NSIS MUI Dev
 
Join Date: Nov 2001
Posts: 3,717
To enumerate directories you have to use FindFirst, FindNext and FindClose.
Joost Verburg is offline   Reply With Quote
Old 8th April 2004, 20:42   #3
dasein
Junior Member
 
Join Date: Apr 2004
Posts: 2
Ah... Thank you very much. I didn't know the Find commands included directories and not just files.

Thanks again.
dasein is offline   Reply With Quote
Old 26th June 2006, 03:10   #4
Brummelchen
Major Dude
 
Join Date: May 2003
Posts: 679
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

Greets, Brummelchen
Brummelchen 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