Many examples here and on Google with Ahk v1 but nothing for v2.
Many examples start from A_ScriptDir or A_WorkingDir but... If I don't know where is but I know its name and ext? (Maybe a pdf downloaded in a different folder than Download for example...).
Here is my solution.
Code: Select all
FileToFind := "FILE_NAME.EXT" ; The file to find
FileFoundedWithCompletePath := FindFileWithCompleteName(FileToFind) ; Call Func
FindFileWithCompleteName(FileNameToFind) {
Loop Parse DriveGetList() { ; 1st Loop: Into all Drives.
PcDisks := (a_loopfield) ; Start w/first Drive found.
Loop Files, PcDisks ":\*.*", "DFR" { ; 2nd Loop: Recurse into all Files, Folders and Subfolders in Dive.
if A_LoopFileName == FileNameToFind { ; If find a file with same name and ext passed to the Func:
FileNameToFind := A_LoopFileFullPath
return FileNameToFind ; Return the file with its complete path.
}
}
}
}
[Mod edit: Removed empty Codebox tags.]