Trouble using filterstring to get folder name from file path

Trouble using filterstring to get folder name from file path

10DSpace
Advisor Advisor
1,717 Views
3 Replies
Message 1 of 4

Trouble using filterstring to get folder name from file path

10DSpace
Advisor
Advisor

I am getting an error message with the following lines of maxscript and I am hoping someone here can tell me what I am doing wrong:

 

fdir = GetSavePath caption: "Select Directory for Export" initialDir:(maxFilePath)
--Now store the folder name to use as the name of the combined .fbx
thefolder = filterstring fdir “\”
thefolderName = thefolder[thefolder.count]

 

The error message is : 

 

-- Type error: FilterString [String to filter] [Tokens] requires String, got: undefined
-- MAXScript callstack:
-- thread data: threadID:12784
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level
-- Error occurred in anonymous codeblock; filename: C:\Users\Dave\AppData\Local\Autodesk\3dsmax\2020 - 64bit\ENU\usermacros\ExportMultipleObjectsforSP.ms; position: 992; line: 26
-- Syntax error: at bad, expected <factor>
-- In line: thefolder = filterstring fdir “\”

 

 

The GetSavePath function works fine and I verified that fdir is in fact storing the file path I select.  

I tried adding an extra "\" (i.e.,  "\\")  in case an escape character is required, but that did not work. Same error message.  I tried to set another variable called folder_string to make sure it is a character string as follows:

 

folder_string = fdir as string

 

and then use that variable in the filterstring  line.   Again it had no effect.  Same error message.   

 

Any guidance would be greatly appreciated. 

 

 

0 Likes
Accepted solutions (1)
1,718 Views
3 Replies
Replies (3)
Message 2 of 4

ads_royje
Alumni
Alumni
Accepted solution

Hi @10DSpace ,

 

indeed, it should take the double backslash as backslash is an escape character.

 

coping your code string I get the same error. Seems to be related to the double quotes ...

Max does seem to like these 

“ ”

and prefer these

" "

can you tell me if this one works for you ?

fdir = @"C:\fold_1\fold_2\fold_3\fold_5\fold_6\"
thefolder = filterstring fdir "\\"
thefolderName = thefolder[thefolder.count]

 

Message 3 of 4

10DSpace
Advisor
Advisor

@ads_royje 

 

Thanks very much! All I did was copy the preferred double quote to my line of code and added back the escape for the "\" and it worked perfectly.  I guess I picked up a strange double quote by cutting and pasting that particular line from a code snippet I found at polycount I think.  I am pretty sure that I would not have noticed the different double quotes character in this lifetime, so you saved me lots of time!   

Message 4 of 4

ads_royje
Alumni
Alumni

Great to read ! 🙂

 

Thank you for your feedback!

0 Likes