[Closed] getSavePath() Folder name
Hi guys,
when I’m selecting a Folder using the getSavePath() function, how could i store the folder name, and not the string path name?
path_name = getSavePath()
--1
filenameFromPath path_name
--2
pathConfig.stripPathToLeaf path_name
--3
getFilenameFile path_name -- (if no dots in the name)
if i understand correctly this should give you just the folder name:
thepath = getsavepath()
thefolder = filterstring thepath “\”
thefolder = thefolder[thefolder.count]
I’m wondering how i could run an infinite loop.
I would like to store all my subfolders into a dotnet tree, by using a code like this:
FolderPath = "C:\blablabla"
fn AddSubFolderFn =(
TheFolder = filenameFromPath FolderPath
SubFolderPaths = getDirectories (FolderPath + "\\*")
for i in SubFolderPaths do
(
FloderPath = i
for i in FolderPath do AddSubFolderFn()
)
)
(i didn’t copy the dotnet part )
I didn’t try it yet, but i think it will run my loop in the 1st subFolder only, like my 2nd exemple below
humm, not an easy one, so I wanted to go my way …
(
fn GatherSubFolder Rootfolder =
(
TreeStruct = GetDirectories (Rootfolder+"\\*")
FinalPath = #()
NeedCheck = #()
--//--
if TreeStruct.count != 0 then
(
for f in 1 to TreeStruct.count do
(
if (GetDirectories (TreeStruct[f]+"\\*")).count > 1 then
(
append NeedCheck TreeStruct[f]
)
else
(
append FinalPath TreeStruct[f]
)
)
)
--//--
while NeedCheck.count != 0 do
(
append FinalPath NeedCheck[1]
SubChild=GetDirectories (NeedCheck[1]+"\\*")
--//--
for f in 1 to SubChild.count do
(
append FinalPath SubChild[f]
--//--
AppChild=GetDirectories (SubChild[f]+"\\*")
--//--
if AppChild.count > 1 then
(
for j in 1 to AppChild.count do
(
append NeedCheck AppChild[j]
)
--//--
)
--//--
)
deleteitem NeedCheck 1
--//--
)
sort FinalPath
FinalPath
)
--//--
myfolder=GatherSubFolder "C:\\"
--//--
clearlistener()
--for f in myfolder do print f
print myfolder.count
-->my count :24616
-->reported count :16451
)
for some reason there seam to be some folder skip… must be some special character…let me know if you found
regard,
Martin Dufour
How to get dirs recursively:
struct dir_scruct (path, name, subs = #())
global dir_list = #()
fn getSubDirectories path:"C:\\Program Files\\Autodesk\\" list:#() =
(
if iskindof path String and doesfileexist path do
(
path = dir_scruct path:path name:(trimRight (pathConfig.stripPathToLeaf path) "\\")
)
if isStruct path do
(
append list path
subs = getDirectories (path.path + "*")
for d in subs do path.subs = getSubDirectories path:d list:path.subs
)
list
)
dir_list = getSubDirectories()
as the result you will get tree of directories with “C:\Program Files\Autodesk\” as root
humm seam incredibly slow …not even terminated at the moment on the entire c drive …do you know what may be causing this ?