Code: Select all
dir = C:\Users\%A_UserName%\Documents
; Just to reproduce a folder with subfolders/files -------
FileCreateDir, %dir%\A
FileCreateDir, %dir%\A\B
FileCreateDir, %dir%\A\B\B1
FileCreateDir, %dir%\A\C
FileCreateDir, %dir%\A\C\C1
FileAppend,, %dir%\A\a.txt
FileAppend,, %dir%\A\B\b.txt
FileAppend,, %dir%\A\B\B1\b1.txt
FileAppend,, %dir%\A\C\c.txt
FileAppend,, %dir%\A\C\C1\c1.txt
; -----------------------------------------------------------------
fileList := {A: {}}
dir := dir "\A"
iterate(dir, "A")
iterate(dir, folder:="")
{
global
Loop, Files, %dir%\*, DFR ; R option for recursive search
{
if (A_LoopFileAttrib == "D")
{
fileList[A_LoopFileName] := []
iterate(A_LoopFileFullPath, A_LoopFileName)
continue
}
else
{
if (A_LoopFileDir != dir)
continue
fileList[folder].push(A_LoopFileName)
}
}
}
I'm trying to store all folders in the object in relation to their parents,
B and C should have been inside A
B1 inside A->B
C1 inside A->C
What i'm trying to achieve is something like this: I wonder if there's a better way to store this other than obj/array
at the ending ill convert this info to json