Click here to Skip to main content
13,298,529 members (43,022 online)
Rate this:
Please Sign up or sign in to vote.
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 23-Sep-12 15:21pm
Updated 23-Sep-12 15:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If the path of your application is "c:\myapplication", then the default current directory is "c:\myapplication"

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 23 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100