Here is the solution!
If your problem is old browsers / IE, you can use sophisticated Amazon solution which will make the functionality available in most of the older browsers /IE:
Here by passing an object to this function you will get back an array of Object property keys and of-course you can get the length from it like a simple array as well!
As you see it is a super simple and very short function!
Managing paths obtained from Adobe Extend-Script, Specially when you want to share these paths with an external 3th application (to do things which aren’t possible with just ExtendScript) is kind of difficult!
For instance let’s say we want to get the Path of an In-Design file being opened (and in front) in in-Design, we may simply do:
But there is obviously 3 (+1 not obvious here!) possible problems with this path (even if you can transfer that variable as easily as shout it out in an alert! look at #3):
the Tilde (~) character at the beginning, an environment variable meaning “Home Directory“, which is not a recognizable standard character in all the different programing environments (for instance it’d be %~dp0 in Batch scripting and user.home, (more or less!) in Java) although it is supposed to be the absolute path using above code!
existence of Slash characters (/) in the path instead of Backslash (\), making it hard (not so much tho!) to send it through a JSON package for example (or save it in a batch file -again- for instance), be-cause in most environments it’d be considered as a escape character and not a path level separator.
It is an object and not a string (apparently!) and you can send, save or sometimes even use the myPathvariable for instance directly! (it will give you an [object] instead of the path, which I guess should be the parent File object itself)
in addition if our file wasn’t in our Desktop folder and was in a disk drive instead, we would have this problem too:
as you can see, an additional Slash character (/) before the Drive letter (c)! which is incomprehensible to me why it is!! but it seems that Extend-Script itself doesn’t have any problem with it, but as I said when you want o communicate with 3th party apps it will become a problem immediately!
So as you may guess there is a lot of solutions for any and each of mentioned problems, but here I just wanted to suggest the most convenient one I figured out after trying a lot of different shenanigan techniques!
Here we used Regular Expression Patterns to Replace() all (by using the g pseudo) the Slashes with Backslashes and by using fsNameinstead of filePatheliminating other problems (like getting “relative paths” (or fake absolutes!) instead of absolutes and the beginning slash character)
And the result:
Please let me know if you have a better idea to this or if you see a problem or something, I appreciate it 😉