Highlighted
Outstanding Contributor.
Outstanding Contributor.
363 views

Possible EXMAScript Editor issue


Hi,

I am coding some filesystem functions in ECMAScript uilizing
java.io.File.

Reading filenames from directories and renaming files is working fine,
but the most simple function is not working (or better it can not be
saved)

function deleteFile(fileName){

file =jFile(fileName);

try
{
jFile(file).delete();
}
catch(exeption)
{
return exeption
}
finally
{}
return '0';
}

Designer comes up with an error in the line containing
jFile(file).delete() reading "Missing name after . operator"

Digging into this it seams that I can put anything behind the dot (.)
bun not "delete"

Any ideas?

Fur sure I have an line var jFile = java.io.File at the beginning of my
ECMAScript and I am using jFile(filename) in my other functions like
getFileNames (.listFlies()) or remaeFile (.renameTo()) without any
trouble!

Regards,

Thorsten


--
tschloesser
------------------------------------------------------------------------
tschloesser's Profile: https://forums.netiq.com/member.php?userid=3232
View this thread: https://forums.netiq.com/showthread.php?t=56325

Labels (1)
0 Likes
7 Replies
Highlighted
Knowledge Partner
Knowledge Partner

Re: Possible EXMAScript Editor issue

'file' != 'filename'.

You pass 'filename' in as an argument, and then you refer to 'file'.

🙂

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Possible EXMAScript Editor issue


ab;269987 Wrote:
> 'file' != 'filename'.
>
> You pass 'filename' in as an argument, and then you refer to 'file'.
>
> 🙂
>
> --
> Good luck.
>
> If you find this post helpful and are logged into the web interface,
> show your appreciation and click on the star below...


Hi Aaron,

thanks for your answer - but I do not see the point in it.

given the following code:


importPackage(java.io);
importPackage(Packages.org.w3c.dom);
importPackage(Packages.com.novell.ldap);
importPackage(Packages.java.lang);
importClass(Packages.com.novell.xml.util.Base64Codec);
importClass(Packages.com.novell.nds.dirxml.driver.XmlDocument);
importClass(Packages.com.novell.xml.dom.DOMWriter);
importClass(java.util.GregorianCalendar);
importClass(java.text.DateFormat);
importClass(java.text.SimpleDateFormat);
importClass(java.lang.System);

var jFile = java.io.File;
function renameFile(fileName){

file =jFile(fileName);

newFileName = jFile(fileName + '.done');

try
{
jFile(file).renameTo(newFileName);
}
catch(exeption)
{
return exeption
}
finally
{}
return '0';
}

function deleteFile(fileName){


file =jFile(fileName);


try
{
jFile(file).delete();
}
catch(exeption)
{
return exeption
}
finally
{}
return '0';
}



I am wondering why the first function is working and I am not able to
save the second one (deleteFile) without any error.
The Error is in line "jFile(file).delete"
If I ignore the error and run the function in ECMAScript builder I get
back that "delet" is not a function - so for whatever reason the tailing
"e" is forgotten.
If I change the code to either jFile(file).delet or jFile(file).deletee
- I reveive the correct error that either delet and/or deletee are no
functions.

So I am still see this as an bug in Designer! Or am I wrong somewhere?


--
tschloesser
------------------------------------------------------------------------
tschloesser's Profile: https://forums.netiq.com/member.php?userid=3232
View this thread: https://forums.netiq.com/showthread.php?t=56325

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: Possible EXMAScript Editor issue

On 07/26/2016 05:54 AM, tschloesser wrote:
>
> thanks for your answer - but I do not see the point in it.


The point is that I could not read, and missed the file = jFile(fileName)
line entirely, so ignore me when I type things as craziness should not be
perpetuated too far.

> given the following code:
>
> importPackage(java.io);
> importPackage(Packages.org.w3c.dom);
> importPackage(Packages.com.novell.ldap);
> importPackage(Packages.java.lang);
> importClass(Packages.com.novell.xml.util.Base64Codec);
> importClass(Packages.com.novell.nds.dirxml.driver.XmlDocument);
> importClass(Packages.com.novell.xml.dom.DOMWriter);
> importClass(java.util.GregorianCalendar);
> importClass(java.text.DateFormat);
> importClass(java.text.SimpleDateFormat);
> importClass(java.lang.System);
>
> var jFile = java.io.File;
> function renameFile(fileName){
>
> file =jFile(fileName);
>
> newFileName = jFile(fileName + '.done');
>
> try
> {
> jFile(file).renameTo(newFileName);
> }
> catch(exeption)
> {
> return exeption
> }
> finally
> {}
> return '0';
> }
>
> function deleteFile(fileName){
>
>
> file =jFile(fileName);
>
>
> try
> {
> jFile(file).delete();


Is there a reason you are casting the variable here again? 'delete' is a
keywords in ECMAscript/JavaScript,so I wonder if the editor, perhaps
correctly even, is complaining about its presence here as being ambiguous
(though it seems clear to us that you mean to use this function on the
jFile-type object). Perhaps see if this can be worked-around by using
Java Reflection stuff:
http://stackoverflow.com/questions/160970/how-do-i-invoke-a-java-method-when-given-the-method-name-as-a-string

Possible sample code:


importClass(java.lang.reflect.Method);
var deleteMethod = java.lang.reflect.Method;
try {
deleteMethod = jFile.getClass().getMethod("delete");
deleteMethod.invoke(file);
}



--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Possible EXMAScript Editor issue

Shouldn't you rather call ...
var file = new jFile(fileName);
var fileDone = new jFile(fileName + '.done');
file.renameTo(fileDone);

vs. jFile(file).renameTo(newFileName);

and

var file = new jFile(fileName);
file.delete();

vs. jFile(file).delete();

Wolfgang

On 26.07.2016 13:54, tschloesser wrote:
>
> ab;269987 Wrote:
>> 'file' != 'filename'.
>>
>> You pass 'filename' in as an argument, and then you refer to 'file'.
>>
>> 🙂
>>
>> --
>> Good luck.
>>
>> If you find this post helpful and are logged into the web interface,
>> show your appreciation and click on the star below...

>
> Hi Aaron,
>
> thanks for your answer - but I do not see the point in it.
>
> given the following code:
>
>
> importPackage(java.io);
> importPackage(Packages.org.w3c.dom);
> importPackage(Packages.com.novell.ldap);
> importPackage(Packages.java.lang);
> importClass(Packages.com.novell.xml.util.Base64Codec);
> importClass(Packages.com.novell.nds.dirxml.driver.XmlDocument);
> importClass(Packages.com.novell.xml.dom.DOMWriter);
> importClass(java.util.GregorianCalendar);
> importClass(java.text.DateFormat);
> importClass(java.text.SimpleDateFormat);
> importClass(java.lang.System);
>
> var jFile = java.io.File;
> function renameFile(fileName){
>
> file =jFile(fileName);
>
> newFileName = jFile(fileName + '.done');
>
> try
> {
> jFile(file).renameTo(newFileName);
> }
> catch(exeption)
> {
> return exeption
> }
> finally
> {}
> return '0';
> }
>
> function deleteFile(fileName){
>
>
> file =jFile(fileName);
>
>
> try
> {
> jFile(file).delete();
> }
> catch(exeption)
> {
> return exeption
> }
> finally
> {}
> return '0';
> }
>
>
>
> I am wondering why the first function is working and I am not able to
> save the second one (deleteFile) without any error.
> The Error is in line "jFile(file).delete"
> If I ignore the error and run the function in ECMAScript builder I get
> back that "delet" is not a function - so for whatever reason the tailing
> "e" is forgotten.
> If I change the code to either jFile(file).delet or jFile(file).deletee
> - I reveive the correct error that either delet and/or deletee are no
> functions.
>
> So I am still see this as an bug in Designer! Or am I wrong somewhere?
>
>

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Possible EXMAScript Editor issue


wschreiber;270040 Wrote:
> Shouldn't you rather call ...
> var file = new jFile(fileName);
> var fileDone = new jFile(fileName + '.done');
> file.renameTo(fileDone);
>
> vs. jFile(file).renameTo(newFileName);
>
> and
>
> var file = new jFile(fileName);
> file.delete();
>
> vs. jFile(file).delete();
>
> Wolfgang
> >


Hi Wolfgang,

thanks for your answer. I do know my code is sometimes not pretty but it
is working - at least the rename function.
I am guessing AB is right, that either ECMAScript and/or the ECMAScript
Builder does not allow the word delete in the code!

I will go ahead and switch to java.nio.file.Files for the delete
function !

Thanks,

Thorsten


--
tschloesser
------------------------------------------------------------------------
tschloesser's Profile: https://forums.netiq.com/member.php?userid=3232
View this thread: https://forums.netiq.com/showthread.php?t=56325

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: Possible EXMAScript Editor issue

tschloesser wrote:

> Digging into this it seams that I can put anything behind the dot (.)
> but not "delete"
>
> Any ideas?


Use java.nio.file.Files instead:

function deleteFile(path){
try {
result = java.nio.file.Files.deleteIfExists(new
java.io.File(path).toPath());
}
catch(exeption) {
return exeption
}
return result;
}



--
http://www.is4it.de/en/solution/identity-access-management/

(If you find this post helpful, please click on the star below.)
______________________________________________
https://www.is4it.de/identity-access-management
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Possible EXMAScript Editor issue


Hi,

tanks a lot! I will try this code asap 😉

Thanks,

Thorsten


--
tschloesser
------------------------------------------------------------------------
tschloesser's Profile: https://forums.netiq.com/member.php?userid=3232
View this thread: https://forums.netiq.com/showthread.php?t=56325

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.