under plugins/file you find a getParent function that will return /Users/harry/Documents. If you substitute that string plus ‘/’ in your path by ‘’, you have your doc name.
I did play with this late yesterday evening and got my desired result using the following to extract the filename :
//choose the file to be uploaded
var file_upload = application.showFileOpenDialog()
//find the position of the last oblique in the file path
//add 1 to it to return the beginning position of the file name
var pathLastSlash = file_upload.lastIndexOf(“/”) + 1
//calculate the string length of filename
var len_filename = file_upload.length - pathLastSlash
//get the file name using the ‘stringRight()’ function
var file_2_upload = utils.stringRight(file_upload, len_filename)
Any feedback on whether the ‘lastIndexOf()’ function is good to use in this instance ?
You’re trying to trigger a function .getParent() on a String object file_upload
When you look in the Plugins/file/JSfile node you will see all the functions that will work with a JSFile object. Also .getParent()
When you look in the Plugins/file node you will see the function plugins.file.convertStringToJSFile()
Hover over this function and you will see details of what the function returns.(see attached image)
So your code should be like this:
var file_upload = “/users/harrycat/desktop/ftp.pdf” ;
var FSfileUploadObject = plugins.file.convertStringToJSFile(file_upload)//returns JSFile Object
var filePath = FSfileUploadObject.getParent() //returns StringObject
Thanks, once again, Maarten for shining some light into a foggy brain.
Having read your explanantion I went to play with the JSFile functions and found ANOTHER one of which I was unaware :
‘getName()’
If I modify my method to :
var fileUpload = “/users/harrycat/desktop/ftp.pdf”
var fileFullPath = plugins.file.convertStringToJSFile(fileUpload)
var getNameOfFile = fileFullPath.getName()
Then I get ‘ftp.pdf’ returned without any of the parsing gymnastics needed from the use of length() and substring() functions !
As you rightly say, there are a zillion ways to skin this particular cat but are there any gotchas to using ‘getName()’ ??
The documentation is a little sparse on File Plugin functions (unless I am looking in the wrong place) and how the File & the JSFile nodes interact.
There is also my relative inexperience in knowing how the different functions operate.
Any info source that anybody could point me to which may help would be much appreciated