i am trying to add an evironment variable to a path inside an ini file, the variable is the current username in Windows which can be accessed via %username%.
so i would like to do path = c:\users\[username variable]\ ...
Will appreciate anyhelp
Use ExpandEnvironmentStrings().
See WritePrivateProfileString() and friends...
Related
Golang on windows. Trying to use
os.Open("%userprofile%\\myfile.txt")
Getting file path not found and golang is not resolving %userprofile% to my C:\users\myusername folder.
To get a file handle, and make your program a little portable too, try
userprofile := os.Getenv("USERPROFILE")
f, err := os.Open(path.Join(userprofile, "myfile.txt"))
The os.Getenv() will read the environment variable and path.Join() will take care of properly constructing the path (so no need to do \\).
Instead of os.Getenv() you might also want to look at os.LookupEnv(). This will tell you if the environment variable you're looking for is empty or simply not existing. A good example of how you can use that to set default values can be found in this answer on SO.
userprofile := os.Getenv("USERPROFILE")
os.Open(userprofile+"\\myfile.txt")
Just written a package to do this. Feedback welcome
https://gitlab.com/stu-b-doo/windowspathenv/
fmt.Println(windowspathenv.Resolve("%USERPROFILE%/Documents"))
// C:\Users\YourName\Documents
Have a look at http://www.golangprograms.com/how-to-set-get-and-list-environment-variables.html
You can read the 'userprofile' environment value and and build the path before passing it to os.Open
I want to write a results CSV file in JMeter which contains a variable in path of the file I write.
E.g.
C:\\Users\\User1\\test-results\\${output}.csv
But I only seem to be able to use predefined variables like ${__time(ddMMyyHHmmss)}
Is there a way to use user defined variables in the path? I have successfully done this to find input files by defining the variable in the test plan node as a User Defined Variable.
I managed to use user defined variable in the path of result file using JMeter 2.9. REPORT is a user defined variable with value REPORT. It gives me file named REPORT.csv
In JMeter 3.1(?) (or Windows?) a double slash is required in the path.
I have used the following successfully:
c:\\jmeter\\results\\${testId}\MyReport.csv
c:\\jmeter\\results\\${testId}\MyReport.csv
c:\\jmeter\\results\\${__time(yyyyMMddHHmm)}\MyReport.csv
c:\\jmeter\\results\\${__time(yyyyMMddHHmm)}.csv
${testId} is a User Defined Variable configured in the Test Plan and set to ${__time(yyyyMMddHHmm)}
I have a environment variable admin_path=/home/myfolder/server. now I need to get the parent path base on the $admin_path in shell script. how can I get it easily? thank you
It's not entirely clear what you want, but I think you are looking for:
${admin_path%/*}
to get the value of admin_path with the trailing path component removed.
I got the filename like this:
_TCHAR filename[_MAX_PATH];
GetModuleFileName(NULL,filename,sizeof(filename));
How do I remove the filename from this full path? Should I use regex?
You can use the Windows shell API function PathRemoveFileSpec to do this. Example usage is listed on the linked page.
Since you use VS++, you can use:
_splitpath and _wsplitpath functions to break apart path
When using FinalBuilder to package our website, I would like it to be able to set the filename when it creates the file set with a variable somewhere else. So the filename would be Website 1.4.exe
Has anyone got this working?
I'm new to FinalBuilder, so if you could give some more info it would be useful - like which action you're using to create the exe.
Have you tried using project variables? From what I've seen you can use them in most FB actions.
At worst you could use the rename file action:
create a new project variable ([Tools\Edit Variables\Add]) called Version and give it a default value
if you need to, you can add a Set Variable action to dynamically set the value of the variable
add a Rename action
set Rename File to the file you want to rename (including path) eg c:\Release.exe
set New Name to Release%Version%.exe
That if the Version project variable is set to 1.4, Release.exe will be renamed to Release1.4.exe