Old 4th December 2001, 08:11   #1
jma
Junior Member
 
Join Date: Dec 2001
Location: Netherlands
Posts: 2
Question Find a directory with a filename

I just discovered NSIS last week and I want to deploy it for an upgrade of our application.

The application can be in any directory on the system and it has no entries in the registery. The only thing I know are the names of the files wich are installed.
Is there a way to find the name of the directory with only the filename.

I tried "GETFULLPATHNAME" but then I need to specify the path with the filename.

Thanks.

Jma.
jma is offline   Reply With Quote
Old 4th December 2001, 08:43   #2
AndiG
Junior Member
 
Join Date: Aug 2001
Posts: 36
Talking

This installer performs a depth-first search: you can use it to find your files...

Name "Find Files"
OutFile "Find Files.exe"
Caption "Find Files"

; Use Show to let user see directories that are scanned
ShowInstDetails Show

ComponentText "Check he drives where you want the installer to scan for files." "" "Select drives to scan:"

; One section to scan drive C
Section "Drive C:"
; set search root directory, omit the trainling backslash
StrCpy $9 "C:"
; start searching
Call FindFiles
SectionEnd

; One section to scan drive D
Section "Drive D:"
; set search root directory, omit the trainling backslash
StrCpy $9 "D:"
; start searching
Call FindFiles
SectionEnd

Function FindFiles

GoAgain:
; look for any files or directories
FindFirst $0 $1 "$9\*.*"
IfErrors NotFound

DoFindNext:
StrCmp $1 "." SkipFile
StrCmp $1 ".." SkipFile

StrCmp $1 "readme.txt" "" CheckDirectory
; perform some action here, ie. replace the readme.txt file

CheckDirectory:
; check if the current file actually is a subdirectory
IfFileExists "$9\$1\*.*" "" SkipFile
; remember on stack
Push "$9\$1"
DetailPrint "$9\$1"

SkipFile:
; continue with next file in current directory
ClearErrors
FindNext $0 $1
IfErrors "" DoFindNext

; no more file in current directory
FindClose $0
NotFound:

; check if we found any subdirectories
Pop $9
IfErrors "" GoAgain
FunctionEnd
AndiG is offline   Reply With Quote
Old 6th December 2001, 11:53   #3
jma
Junior Member
 
Join Date: Dec 2001
Location: Netherlands
Posts: 2
Thumbs up

Thanks!

Just what I needed .
jma is offline   Reply With Quote
Old 6th December 2001, 13:03   #4
Angry Weasel
Senior Member
 
Join Date: Oct 2001
Posts: 145
If you make a full installer for your product in NSIS, make sure you do the following to avoid this dilemma:
code:

; This will write a registry string with the path to your product.
; You can use HKEY_LOCAL_MACHINE instead of HKLM if you wanna be
; difficult.

WriteRegStr HKLM "SOFTWARE\CompanyName\ProductName" "InstPath" "$INSTDIR"
; Obviously, unless your product is called "ProductName" and your company called "CompanyName" you're gonna need to change it to the name of your product and company.




And when you want to make an upgrade for your product, use this:
code:

; This will read your product's install path to the user variable $5
; Why $5? Because I like 5.

ReadRegStr $5 HKLM "SOFTWARE\CompanyName\ProductName" "InstPath"



You can then use InstallDir in the following way

InstallDir "$5"

in order to install the upgrade to the same directory.
Angry Weasel 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