PDA

View Full Version : getSavePath() Folder name


holycause
08-09-2009, 08:10 PM
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?

SoLiTuDe
08-09-2009, 09:07 PM
if i understand correctly this should give you just the folder name:

thepath = getsavepath()
thefolder = filterstring thepath "\\"
thefolder = thefolder[thefolder.count]

holycause
08-09-2009, 09:23 PM
Thanks Ian, I'll try it :D

holycause
08-09-2009, 09:59 PM
it's working perfectly. Thanks a lot. :D

denisT
08-09-2009, 10:44 PM
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)

SoLiTuDe
08-10-2009, 02:12 AM
^^nice... forgot about all of those. :thumbsup:

holycause
08-10-2009, 04:18 PM
nice. thanks a lot as well Denis ;)

holycause
08-10-2009, 05:40 PM
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

http://aespid.com/Perso/MS/InfiniteArray.jpg

martroyx
08-10-2009, 07:39 PM
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

denisT
08-10-2009, 07:59 PM
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

martroyx
08-10-2009, 08:08 PM
humm seam incredibly slow ...not even terminated at the moment on the entire c drive ...do you know what may be causing this ?

denisT
08-10-2009, 08:16 PM
humm seam incredibly slow ...not even terminated at the moment on the entire c drive ...do you know what may be causing this ?

first time is very slow... and i don't see a reason why...

MarcoBrunetta
08-10-2009, 08:21 PM
You could try the .net directory class.... maybe that's faster? I think it's "system.io.directory" and it has a getDirectories method.

EDIT: http://msdn.microsoft.com/en-us/library/system.io.directory.aspx

martroyx
08-10-2009, 08:24 PM
ok then , thank , I check this out a bit more :-)

martroyx
08-10-2009, 08:27 PM
ho really, then I definitely need to check this out , because I needed this stuff at the moment anyway , Thank guy !

denisT
08-10-2009, 08:42 PM
You could try the .net directory class.... maybe that's faster? I think it's "system.io.directory" and it has a getDirectories method.

EDIT: http://msdn.microsoft.com/en-us/library/system.io.directory.aspx

i've checked .NET...
(dotnetclass "system.io.directory").GetDirectories ... is 2.5 times slower then MXS getDirectories...

martroyx
08-10-2009, 08:48 PM
i've checked .NET...
(dotnetclass "system.io.directory").GetDirectories ... is 2.5 times slower then MXS getDirectories...


damn ... I incorporated in mine ...anyway I found my mistake was missing = on last part now the count is good :-)


(
fn GatherSubFolder Rootfolder =
(
DirClass=dotnetclass "System.IO.Directory"
--//--
TreeStruct=DirClass.GetDirectories Rootfolder
FinalPath = #()
NeedCheck = #()
--//--
if TreeStruct.count != 0 then
(
for f in 1 to TreeStruct.count do
(
if (DirClass.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=DirClass.GetDirectories NeedCheck[1]
--//--
for f in 1 to SubChild.count do
(
append FinalPath SubChild[f]
AppChild=DirClass.GetDirectories SubChild[f]
--//--
if AppChild.count >= 1 then join NeedCheck AppChild
--//--
)
deleteitem NeedCheck 1
--//--
)
sort FinalPath
FinalPath
)
--//--
global myfolder=GatherSubFolder "C:\\"
--//--
clearlistener()
--for f in myfolder do print f
print myfolder.count
-->my count :24616
-->reported count :24618
)



:-)

holycause
08-10-2009, 09:03 PM
Superbe Martin ;)

Really nice :D

martroyx
08-10-2009, 09:08 PM
Thank, I put back the maxscript getdirectory since it seam to be faster :)


(
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 join NeedCheck AppChild
)
deleteitem NeedCheck 1
--//--
)
sort FinalPath
FinalPath
)
--//--
global myfolder=GatherSubFolder "C:\\"
--//--
clearlistener()
--for f in myfolder do print f
print myfolder.count
-->my count :24616
-->reported count :24618
)

denisT
08-10-2009, 09:09 PM
35% faster!!!

holycause
08-14-2009, 09:44 PM
i made this script.

http://aespid.com/Perso/MS/MSTreeView.jpg (http://aespid.com/Perso/MS/MSTreeView.jpg)


I ll add later some more stuff

martroyx
08-15-2009, 03:53 PM
hehe , I like this script , very usefull :thumbsup:

su37
08-16-2009, 04:40 AM
I like the script,But there is no directory of memory function, if there is all the better

holycause
08-16-2009, 07:02 AM
I know, I already added it.
But i would like to add some more stuff before to upload it. ;)

martroyx
08-16-2009, 06:48 PM
I know, I already added it.
But i would like to add some more stuff before to upload it. ;)


I hope you don't mind , I customized mine a bit ... fell free to build on top of it if you want
or tear it apart :)

Cheer,
Martin

holycause
08-16-2009, 06:55 PM
Thanks Martin.

I'm working on the properties Rollout. So i disabled it. My code is really messy now, i'm doing a lot of tests.

I also add an option to edit your script, instead of running it. (The checkbutton in the middle)

I've no idea how to update a dotnet treeview.
I m using an ini file to store my folders paths (only the main ones).
And in my properties panel, i can delete them into the ini, but i m wondering how to update it.

I tried by closing and creating my floater again, but it doesn t work, because it can't find my Rollout or my Floater, since i'm calling them from an other Rollout

BTW Martin, I ll add it on yours ;)
We could all of us, add a tab with some personal special tools in it and make a bigger one from it ^^

martroyx
08-16-2009, 07:36 PM
I've no idea how to update a dotnet treeview.


well, some time ago , I used a timer that checked the file count and updated the list if the count changed but that was on a single folder ...don't know how this would react on that many folder !!

SoLiTuDe
08-16-2009, 08:00 PM
Thanks Martin.

I've no idea how to update a dotnet treeview.
I m using an ini file to store my folders paths (only the main ones).
And in my properties panel, i can delete them into the ini, but i m wondering how to update it.


not sure if this is exactly what you mean, but I usually have a function that generates my arrays (say create an array of the folders and files), and then another function that actually tells the treeview to update (actually rebuild) based on those arrays. I then usually have an update button to update my lists...

martroyx
08-16-2009, 08:14 PM
I used something like this to update the treeview :)


fn timer_evaluate f =
(
local TheSelectedNodeName = tv.selectednode.text
local FilesCount = f

for f in 1 to SearchDirectory.count do
(
FilesCount += (getFiles (SearchDirectory[f]+"*.ms")).count
)

if Treeview_count != FilesCount do
(
update_treeview()
SelectNodeByName TheSelectedNodeName
)

)

martroyx
08-17-2009, 05:51 PM
In fact, the little getFilesRecursive func from the maxscript help does gather all of the
subfolder ...I was in the impression it gathered just the first subchild ...but, no, it seam to work prety well :-)

martroyx
08-17-2009, 07:46 PM
---------------------------------------------
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 join NeedCheck AppChild
)
--//--
deleteitem NeedCheck 1
)
--//--
sort FinalPath
)
---------------------------------------------
fn getFolderRecursive root=
(
dir_array=GetDirectories (root+"/*")
for d in dir_array do join dir_array (GetDirectories (d+"/*"))
--//--
sort dir_array
)
---------------------------------------------
xx=yy=undefined
gc()
ProcStart = timestamp()
xx=GatherSubFolder "c:\\"
print xx.count
ProcEnd = timestamp()
format("Processing took : "+(((ProcEnd-ProcStart) / 1000.0)as string)+" Secondes"+"\n")
--24747
--Processing took : 4.656 Secondes
gc()
ProcStart = timestamp()
yy=getFolderRecursive "c:\\"
print yy.count
ProcEnd = timestamp()
format("Processing took : "+(((ProcEnd-ProcStart) / 1000.0)as string)+" Secondes"+"\n")
--24756
--Processing took : 7.531 Secondes



windows report 24749 by selecting all the files including hidden one and showing property.
well, so who's right here?...I don't get it, anyone ? :banghead:

edit : speed is prety much the same ....I was not trying to win by filling up memory :-) but still that folder thing is very strange ...maybe I got some intruder folder on my pc ...can anyone confirm this ?

edit2 : seam the second count is the right one, but that mean the explorer don't see all the folder that's weird :curious:

martroyx
08-18-2009, 11:58 PM
Hi Ruben,

I've continued to improve the toolbar , I just added some kind of hack to permit resize of the toolbar and the viewport at the same time

http://www.youtube.com/watch?v=iZeYU9LjrtI

do you guy know of a simple way of doing this because it pretty unstable at the moment , it keep crashing and freezing all the time :-)

do you think it's a good idea ?

Martin

denisT
08-19-2009, 12:27 AM
Hi Ruben,

I've continued to improve the toolbar , I just added some kind of hack to permit resize of the toolbar and the viewport at the same time

http://www.youtube.com/watch?v=iZeYU9LjrtI

do you guy know of a simple way of doing this because it pretty unstable at the moment , it keep crashing and freezing all the time :-)

do you think it's a good idea ?

Martin

What the hack is? You can't change size of window which is registered as dialogBar... UnregisterDialogBar -> Change window size -> RegisterDialogBar back... it's not a good idea IMHO.

martroyx
08-19-2009, 12:47 AM
...Change window size -> RegisterDialogBar back


hehe that's the hack no need for this, I sure need to load an assembly to play with the windows size and location throught ...but seam to freeze for no reason when I resize the viewport too much ... I look into this at the moment :-)

martroyx
08-19-2009, 07:32 AM
Ho well, it create viewport distortion ...so I guess it was not a good idea :curious:
but, anyway it was fun :-)

CGTalk Moderation
08-19-2009, 07:32 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.