AutoHotKey: Method of finding file upwards, recursively, using loop
-
18-09-2019 - |
Question
I am working through the AHK docs but am having a hard time finding a fairly simple way to find the path to a target file in a parent directory, given a starting directory.
For example:
Starting in C:\a\b\c\d\e\f\g\
I want to find the path of root.txt where:
C:\a\b\c\root.txt
I want to return C:\a\b\c\
[by the way I do not know where root.txt lives]
Solution
I would make a loop and add "..\" to the current directory path each time.
It works in autohotkey, i always use it.
For example, I have my scripts in one directory, and images in another on the same level.
So my images paths are always:
%A_ScriptDir%\..\images\
OTHER TIPS
http://www.autohotkey.com/docs/commands/SplitPath.htm
Your entire path would be the input variable. and your desired path would be given to you as OutDir