Find path from where .exe is run Autohotkey - autohotkey

I have a compiled ahk script in which I use %_A_WorkingDir% to get the current working directory. But now I'm calling the .exe from another file two folders up so %_A_WorkingDir% returns the directory that is two folders up, not the location of the actual .exe. How do I fix this issue?

A_WorkingDir is the directory in which the script is currently
working. You can change it by using
the command SetWorkingDir.
A_ScriptDir is the full path of the directory where the script is in.
A_ScriptFullPath is the full path of the current script.
https://autohotkey.com/docs/Variables.htm#prop

Related

Loading files in Matlab

In my code I want to indicate paths to files that are independent on which computer the code is run. In other words, I want the script to operate only in the folder where it is located because my friend's computer can have different drive names, folders' names etc. The task is to load files by indicating where they are located. I thought this would work: "load("..\Folder\file.mat")". However, Matlab gives an error
Error using load
'..\Folder\file.mat' is not found in the current folder or on the MATLAB path, but exists in:
D:\D (synced)\Folder 3\Matlab
D:\D (synced)\Folder 3\Data
Change the MATLAB current folder or add its folder to the MATLAB path.
I checked and file.mat is in Folder which is located in the same directory as the script that I run.
Could someone tell how to make all paths independent on what computer they are run and avoid the error?
I suppose that both your script and file are in the folder Folder.
To make it operating system independent, you could use mfilename to retrieve the path of your script, and use fullfile to concatenate the path with the file name.
p = mfilename( 'fullpath');
file = load( fullfile( p, 'file.mat'));

How to call an executable with Dll from a directory without this dll

I have a working directory a and
I have a directory b with an exutable and a dll which is used by the executable.
I want to launch the executable in the working directory.
With powershell I do that:
$env::path += ";C:\path\to\the\directory b"
Now I try to launch the executable from directory a
executableName
the programm is launched but it fails to work because it can't find the dll.
How can I fix the problem?
I have contacted the company that has done this executable file.
The problem comes from the file.
It's not a path related problem.

Powershell accessing executable in wrong directory despite $PATH variable being set

I was trying to get vim going in powershell, and so I added C:\Program Files (x86)\Vim\vim82 to the PATH. However, when I try to run vim in powershell, it goes to the wrong folder, C:\Program Files (x86)\vim\vim80\vim.exe (note that it is incorrectly vim80 instead of the correct folder name of vim82).
There's nothing else in the path that would send it to vim80, and the vim80 folder doesn't even exist on my computer, so I'm kind of confused as to how that might happen...
And the desired vim.exe executable does run successfully if I actually navigate to the correct vim82 folder.

Change Directory to Folder Containing PowerShell Script - Regardless of Where That Folder Is Located

I have a script that I've created to prep our customer's servers for a software install. Part of this requires the script to be run as administrator, so just instructing people to click "Run With Powershell" doesn't get the job done. The script is in a folder with a number of .ini files that the script needs to copy to different server locations. If I just right-click the Powershell script and select "Run With Powershell," it is able to find the files and copy them without issue. Unfortunately, if I open the script in ISE, it opens with a default directory of C:\users\user, and I can't seem to copy those .ini files without first running a change directory command to get us to the folder that the script and the .ini files are in. But I'd like our installation techs to be able to run this without worrying about the exact location they initially drop these folders. I'd also like them to not have to worry about changing the directory manually in PowerShell. Some of our customers have multiple drives, and it might make sense to put this stuff on something other than the C drive, so it's hard to tell where this folder might end up. But I'm not sure of a command that will get me to the directory of the *.ps1 file, without knowing where that file is beforehand... Anyone have a suggestion?
You can use $PSScriptRoot that will have the location of the directory where the script is located.
This is referenced in the following post:
How can I get the file system location of a PowerShell script?

Accessing folders via MATLAB

I am trying to access some .m folders that I have downloaded into Downloads. How can I access this folder and run the files using cd similar to how I would on a Terminal (MacOS)? The same statements don't work.
All of the regular commands for linux should work.
ls, dir, cd 'your folder goes here' , cd ,, , cd.. etc
You need to pass the absolute path of your Downloads folder, e.g.:
current_dir = pwd;
cd('C:\Users\you_username\Downloads')
Then, you'll be able to access the files in that folder. When you are finished, you can then return to your original folder with:
cd(current_dir);
An alternative is to add the Downloads folder to your MATLAB path with addpath. You should then be able to access files in there from any directory of your choosing without having to cd. If you want to make that change to the MATLAB path permanent, use savepath afterwards to save the MATLAB path for future sessions.