I have done some more modifications to suit my purpose, which was to rename the files to include the folder path it had.
i.e.
root
a
1
b
1
2
would become
root
a-1
b-1
b-2
here's the code for it
FlattenWithFolderNames.ahk
fileselectfolder,MyFold,::{20d04fe0-3aea-1069-a2d8-08002b30309d}
SetWorkingDir, %MyFold%
loop, *.*,0,1
{
parentpath := RegExReplace(A_LoopFileDir,"\\","-")
;StringReplace, parentpath, A_LoopFileDir, \,-,All
newname = %parentpath%-%A_LoopFileName%
;msgbox %newname%
If a_loopfiledir <>
filemove, %a_loopfilefullpath%,%newname%
}
loop, %myfold%\*.*,2,1
fileremovedir, %a_loopfilefullpath%,1
exitapp