Click here to Skip to main content
16,011,626 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am in the process of writing a custom installer program in which I will use MSIInstall function. Unfortunately the function requires the path of the package to install. If the current directorymeans the directory whre execution is taking place then that may solve the problem. I once used a dot to represent current directory in a file open operation but the open operation failed. Please, how does one represent current directory in a way that it will make it possible for a file open operation to succeed or the MSIInstall function to succeed.
Posted
Updated 23-Sep-12 14:26pm
v2

A path defines the location of a directory or file on one of your drives. A path in windows can be absolute, or relative. A path is absolute when it starts with the drive letter like "C:\windows\temp". A path is relative when it doesn't contain a drive notation like "x\mydir\something.bin".

The current directory is a "per process string variable" that contains an absolute path to a directory like: "c:\windows". Basically 99.999% of windows/CRT functions that require you to pass in some file/directory path as a parameter make use of the current directory because if one of the path parameters is a relative path, then the function will transform it to an absolute path by prefixing it with the current directory. Example: If you call fopen("x\\x.txt", "r") and the current directory is "C:\docs" then fopen will use the "c:\docs\x\x.txt" file. If fopen uses an absolute pathname then the current direcctory wont be used at all. Right? You can anytime set the current directory of your process with the SetCurrentDirectory() function, and you can get its value with GetCurrentDirectory().

Note that the current directry has nothing to do with the directory that contains the executable. These are often the same however. When a running program starts another process it can specify the initial current directory of the process to launch. And the process itself can change it later as I described.

Flaws: The current directory is a per process variable so its shared between your threads if your program is multithreaded, for this reason I never liked the concept of having a current directory, I usually set it at most once at program startup and then I use absolute pathnames everywhere. MS knows this flaw and they are about to eliminate it from their new APIs.
 
Share this answer
 
If the path of your application is "c:\myapplication", then the default current directory is "c:\myapplication"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900