Archive: Find a directory with a filename


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.


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


Thanks!

Just what I needed .
:cool:


If you make a full installer for your product in NSIS, make sure you do the following to avoid this dilemma:


; 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:

; 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.