Archive: locate function question


locate function question
i used instructor's http://nsis.sourceforge.net/archive/viewpage.php?pageid=527 function to create a textfile with all files and subdirs of a drive or directory.

my problem is, that i don't see a way to sort the files as desired. by default i get an alphabetically sorted list, unregarding whether it's a file or a folder.

C:\WINDOWS
C:\WINDOWS\0.log
C:\WINDOWS\addins
C:\WINDOWS\Application Compatibility Scripts
C:\WINDOWS\AppPatch
C:\WINDOWS\aspnetocm.log

my requirement is a script that sorts differently: subdirs shouldn't be accessed until all files in a directory were indexed.
C:\WINDOWS
C:\WINDOWS\0.log
C:\WINDOWS\aspnetocm.log
(all other files in C:\WINDOWS)

C:\WINDOWS\addins
(all files in C:\WINDOWS\addins)

C:\WINDOWS\Application Compatibility Scripts
(all files in C:\WINDOWS\Application Compatibility Scripts)

C:\WINDOWS\Application Compatibility Scripts\Install
(all files in C:\WINDOWS\Application Compatibility Scripts\Install)

..

can this be done?

If you need just to make list of files and directories, use command processor (command.com or cmd.exe):

Name "Output"
OutFile "Output.exe"

Function FileOemToChar
!define FileOemToChar `!insertmacro FileOemToCharCall`

!macro FileOemToCharCall _FILE
Push `${_FILE}`
Call FileOemToChar
!macroend

Exch $0
Push $1
Push $2
Push $3

FileOpen $1 $0 a
FileSeek $1 0 END $2
System::Alloc $2
Pop $3

FileSeek $1 0 SET
System::Call 'kernel32::ReadFile(i r1, i r3, i $2, t.,)'
System::Call 'user32::OemToCharBuff(i r3, i r3, i $2)'
FileSeek $1 0 SET
System::Call 'kernel32::WriteFile(i r1, i r3, i $2, t.,)'

System::Free $3
FileClose $1

Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

Section
GetTempFileName $0
ReadEnvStr $1 COMSPEC
nsExec::Exec '"$1" /C DIR "$STARTMENU" /A /B /S /ON>"$0"'
${FileOemToChar} "$0"

Exec 'Notepad.exe "$0"'
SectionEnd

well it's not just a list that i need, thought i keep the example simple.

when the user can specifiy two things in a dialog, the source directory and a target location:

source example:
c:\test
c:\test\file1.txt
c:\test\subdir1\file2.txt
c:\test\subdir1\subdir2\file3.txt

target example:
http://www.myurl.no

from this information, i want to create textfile of the following scheme.

http://www.myurl.no/file1.txt
outdir:subdir1
http://www.myurl.no/subdir1/file2.txt
outdir:subdir1\subdir2
http://www.myurl.no/subdir1/subdir2/file3.txt

Fuff:

Name "Output"
OutFile "Output.exe"

!include "FileFunc.nsh"
!insertmacro GetParent

!include "TextFunc.nsh"
!insertmacro LineFind
!insertmacro TrimNewLines

!include "WordFunc.nsh"
!insertmacro WordReplace

Section
StrCpy $R0 "$SMPROGRAMS"
StrCpy $R1 "http://www.myurl.no"
StrLen $R2 $R0
StrCpy $R3 ''

GetTempFileName $0
ReadEnvStr $1 COMSPEC
nsExec::Exec '"$1" /C DIR "$R0" /A-D /B /S /ON>"$0"'

${LineFind} "$0" "" "1:-1" "LineFindCallback"

Exec 'Notepad.exe "$0"'
SectionEnd

Function LineFindCallback
System::Call 'user32::OemToChar(t R9, t .R9)'
${TrimNewLines} "$R9" $R9
StrCpy $R9 $R9 '' $R2

${GetParent} "$R9" $1
StrCpy $1 $1 '' 1
StrCmp $R3 $1 +3
FileWrite $R4 "outdir:$1$\r$\n"
StrCpy $R3 $1

${WordReplace} "$R9" " " "%20" "+" $R9
${WordReplace} "$R9" "\" "/" "+" $R9
StrCpy $R9 "$R1$R9$\r$\n"

Push 0
FunctionEnd

wow, that's more than i asked for.. feeling guilty. you're a mad machine, thank you!