Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

[FEATURE] file name with subdir


#1

Hello,

I’m looking for a way to store log files in relative subdirectory ( ‘.\log’ ) for application. Currently I can do it only by specifying absolute path in connection string. The drawback is that it is installation specific value.
Is there any way to define log files location without specifying full path? If no, could you add such a feature?

best regards
Piotr Rezmer


#2

Piotr,

Relative paths work fine already. The only thing to know is that the path is relative to the current working directory of a process and this does not necessarily match the directory of the executable. So, if you change the working directory of your process to the installation directory on process startup (with SetCurrentDir in Delphi), relative paths should work as expected. Hope that helps!

Regards,
Tobias


#3

By the way, one thing to consider are the access rights in this scenario. If you install your application to ‘Program Files’ or something similar, newer Windows versions won’t allow you to write log files under your installation directory (as regular user, at least).

Regards,
Tobias


#4

Thanks, I’ll try with setCurrentDir(). I’m using smartInspect with NT Service application, so working directory is usually .

By the way, would it be possible to use Si.setVariable() method? I’m trying to do it, but have some problems.

best regards
Piotr Rezmer


#5

That would be possible as well. This makes sense if you are using configuration files (and then replace the variable with a real value at runtime). What problems do you see when using the variables?

Regards,
Tobias


#6

I’ve solved it already. I forgot to add backslash to the variable, while my configuration file used:

filename= $path$appName

By the way, using setCurrentDir() might be unsafe, when application changes current dir in during other operations, besides other problems might appear when ConfigurationTimer is used

best regards
Piotr Rezmer


#7

Yes, using the connection variables is probably safer than setting the working directory (although I think one shouldn’t change the working directory somewhere in the middle of an application, of course you can’t always know what some third-party code is doing).

Regards,
Tobias