Archive: pathname of file without the filename itself


pathname of file without the filename itself
I am trying to determine if a file exists on a system, get the path of that file if it does exist, and then present that path as the installation directory (for user to change if they wish). I cannot find a way to get just the pathname of a file, without the filename itself.

So far, I have this:
Function .onInit
; The default installation directory
GetFullPathName $1 rcdigits.exe
IfErrors 0 exists
StrCpy $INSTDIR $PROGRAMFILES\rcdigits
Goto dorest
exists:
StrCpy $INSTDIR $1
dorest:
FunctionEnd

This works, but $1 contains say c:\ItIsHere\rcdigits.exe . I want to just get c:\ItIsHere

Can someone help me? I have just started using NSIS, think it's dynamite!
Rich


Try using $EXEDIR


First of all, welcome to our community :D

To get the directory in which a file is, use GetParent from your functions.html file in your NSIS directory.


Thanks for the tip! I'll give it a shot.


I'm sorry, I was mistaken that the code in my question was working. It only works if the file I'm looking for is in the directory that I am running the install from.

So, I guess I need to rephrase my question. How can I get the install program to search the system for a particular file (e.g. myprogram.exe) and return to me the full path of where it was found?

The function you mentioned will be great for isolating just the path, but I cannot now figure out how to do the search itself. I tried GetFullPathName and also SearchPath, but they do not seem to search outside the dir of the install program. FindFirst sounds perfect, but it does not return the path.

I'm hoping that there is some function to do it, instead of having to code some recursive directory stepping thing myself (assuming such a thing is possible in NSIS).

I used to distribute a freeware program via just a zip file, with no install routine. Users would just unzip it into any dir they wanted. Now I want to use NSIS to build an installation routine, but I would like it to find wherever the program was installed earlier, so i can present it to the user as the default for the new install using the install program.

Sorry about the long-winded question. :-)


Sorry, the only way that I know of is by using a recursive function... SearchPath only searches the directories in the path.

The best way to do this is get some value from the registry, but I doubt you have it if you used a zip file before.


Thanks for your help. It's probably not worth trying to code some search function. After the first running of the new install routine, I'll have the info stored in the registry, so everything will be cool after that.

In truth, another reason I wanted to know if this were possible was that it seemed like a way to write an install that did not ever use the registry. Some people object to shareware/freeware making registry entries, and I thought I might be able to avoid it and still make it look more or less professional. It seems that even an uninstall might be possible, except that its name wouldn't show up on the Add/Remove list (you'd just have a shortcut to the uninstall on the Start submenu). But, I guess it's not doable without more trouble than it's worth.

Thanks again!
Rich


How about writing an installer that creates an ini file in the user's windows directory or other location NSIS can find? You can later read this file for the installation location. During the first installation, you can let users browse to their existing program directory or just let them accept your default location.


Yes, that would work. But I also wanted to avoid writing anything in the user's system directory. I am already using a "local" ini file so the program remembers stuff each time, but it's in the installation dir. I guess I'm trying to be too "benign." You hear a lot of screaming about shareware modifying the registry and placing stuff all over the system, but you also hear people complain if there isn't an Uninstall routine. So, you can't please everyone, I guess. Thanks for the suggestions :-)


Just thought I'd mention that I took your advice, Cchian, and set up an ini file in the Windows directory. It contains just the instdir info. I read this at startup of the install. This workes great and is pretty unintrusive. I even was able to set up an Uninstall, by setting up a shortcut to the uninstall on a subdir for my program under the Start->Programs menu. The only thing I lose by doing this is that my product does not show up on the Add/Remove list, since I made no registry entry for it. I like this OK, and it's nice that NSIS is flexible enough to allow such fine tuning!