Hi Markus,
Thanks for your explanations!
It's not quite clear to me why filePath.indexOf("C:\users\") returns Position 0.
Line if (filePath.indexOf($.getenv('AppData'))==0) started working only after I defined a system variable called AppData.
I'd like to test your suggestion to use File.copy() instead of saving the file.
Interestingly enough, I didn't see the File.copy() method in the Scripting Guide, nor in the Javascript Tools Guide.
So, assuming the open file is defined as:
var doc = app.ActiveDoc;
and the target folder to copy the file to is defined as:
var docLib = "T:\\My_UG\\Sources\\";
I've created a new file object:
var oFile = new File(doc.Name);
To copy the file over to the network folder, I tried:
oFile.copy(docLib);
For some reason, it doesn't work. Any idea why?
Thank you!!
Hi Rombanks,
indexOf Returns 0 in this case, as the string starts with the string provided as parameter. Strings starts at the first position, and the first position in an JavaScript array is 0 (not 1). This is by Definition.
this is what "ObjectModel Viewer" (F1 in ESTK) tells for File.copy
File.copy (target: string ): Boolean Core JavaScript Classes Copies this object’s referenced file to the specified target location. Resolves any aliases to find the source file. If a file exists at the target location, it is overwritten. Returns true if the copy was successful. target: Data Type: string or File A string with the URI path to the target location, or a File object that references the target location. Example: aFile.copy(target)
File.copy expects and URI or a File object, so do this
var oFile = new File(doc.Name);
oFile.copy(new File(docLib));
or
oFile.copy(new File(docLib).toString());
Make sure, docLib is a file path not not a path to a Folder. docLib sounds like a Folder path. this doesn't work. a file Name is expected here.
File.copy works with an URI not with a Windows file path. An URI starts with file://c:/somepath or ~AppData\Users.... etc.
So this should also work with Network paths, but I haven't testet it yet.
$.getenv reads environment variables from the system. %appdata% is defined by default. not sure why this doesn't work in your environment. Put the string in JavaScript console and see what the result is.