Old 14th March 2011, 17:15   #1
Kazegarou
Junior Member
 
Join Date: Feb 2011
Posts: 4
Getting list of subfolders in a folder

Hello all,

Can you please tell me if there's a NSIS script to get a list or get the name, one at a time, of each subfolder inside a folder? Only one level below.

As in input -> $DOCUMENTS
Output:
C:\Users\..\My Documents\My Pictures
C:\Users\..\My Documents\My Music
C:\Users\..\My Documents\Downloads...

...and so on.

I even tried redirecting the output of 'dir "$DOCUMENTS" /ad /b > "$INSTDIR\directories.txt"' with nsExex::Exec and plain Exec... to no avail. If the file was created, all I'd have to do is a loop to read each line from it, but I didn't manage to get that to work either.

Thanks in advance.
Kazegarou is offline   Reply With Quote
Old 14th March 2011, 18:14   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
FindFirst $0 $1 "$INSTDIR\*.*"
loop:
StrCmp $1 "" done
${If} ${FileExists} "$1\*.*"
DetailPrint "Subdir found: $1"
${EndIf}
FindNext $0 $1
Goto loop
done:
FindClose $0
MSG is offline   Reply With Quote
Old 9th October 2016, 00:34   #3
gadjah
Junior Member
 
Join Date: Oct 2016
Posts: 1
There's minor flaw that can cause you hours to debug in above code, here's a "7 hours worth" of fix:

FindFirst $0 $1 "$INSTDIR\*.*"
loop:
StrCmp $1 "" done
${If} ${FileExists} "$INSTDIR\$1\*.*"
DetailPrint "Subdir found: $INSTDIR\$1"
${EndIf}
FindNext $0 $1
Goto loop
done:
FindClose $0

Yeah, that "$INSTDIR\" omission makes the above codes only get two subdirs: . (current) and .. (parent). ...And got me really anxious for 7 hours! Damn, I'm such a dummy coder.
gadjah is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
dir, exec, folder, prompt, subfolder

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