Error -1415 and How to check existence of local files

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
miscthings
Posts: 4
Joined: Thu Jun 22, 2017 6:56 pm

Error -1415 and How to check existence of local files

Post by miscthings » Thu Jun 22, 2017 7:28 pm

Hello, been lurking all day to try to find an answer to my problem but I can't seem to figure it out, so I thought I'd post on the forums.

I am using the trial client of iMacros Browser at the moment.
FCI:
Windows 7 Enterprise - English
iMacros Browser V11.5.499.3066
Emulating IE11

Basically I am trying to use iMacros to do a repetitive task of downloading .pdfs from a website over and over.

This macro would run periodically, but the main issue is how to deal with duplicate documents. Ideally, the solution for me would be to find out if there is a way to check a local directory for a file name, and if it exists, skip this file and continue the loop to the next. My exact question is pretty much asked here, but this is for the Firefox version, and I'm wondering if there's a method for non-JS iMacro code (or, at least, I can't seem to figure out EVAL syntax to write the if check).
https://stackoverflow.com/questions/386 ... ox-imacros

If iMacros is incapable of doing it, then I guess I have no choice but to overwrite the files, which is still technically okay for me, except that iMacros is deleting files from my local directory sometimes. With my existing code, when I downloaded a file, I would do it the first time, get the file successfully, but on the second download (same file), it would sometimes delete the existing file from my directory, and return Error -1415.

I could paste my whole code but really the only relevant line is probably the ONDOWNLOAD line:

Code: Select all

ONDOWNLOAD FOLDER=C:\Users\hob\Desktop\testDir FILE={{acc}}DUE{{date}} WAIT=YES
It's kind of random when it deletes a file, sometimes it will just overwrite without any errors but sometimes the error will happen and stop the script.
Here is the exact copy of the error in my client:

Code: Select all

Error -1415: Cannot find downloaded file 'C:\Users\hob\Desktop\testDir\2241387642DUEJun 26 2017.pdf'. Line 21: ONDOWNLOAD FOLDER=C:\Users\hob\Desktop\testDir FILE={{acc}}DUE{{date}} WAIT=YES
So basically:
1.) Is there a way to check for a file in a local directory, and provide action accordingly based on true/false?
2.) Error -1415 does not exist in iMacro error database, but this isn't a problem if I can figure out the check before downloading at all
3.) What is this .bak file also being generated, is there a way to not download this?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Error -1415 and How to check existence of local files

Post by chivracq » Fri Jun 23, 2017 12:31 am

miscthings wrote:Hello, been lurking all day to try to find an answer to my problem but I can't seem to figure it out, so I thought I'd post on the forums.

I am using the trial client of iMacros Browser at the moment.
FCI:

Code: Select all

Windows 7 Enterprise - English
iMacros Browser V11.5.499.3066
Emulating IE11
Basically I am trying to use iMacros to do a repetitive task of downloading .pdfs from a website over and over.

This macro would run periodically, but the main issue is how to deal with duplicate documents. Ideally, the solution for me would be to find out if there is a way to check a local directory for a file name, and if it exists, skip this file and continue the loop to the next. My exact question is pretty much asked here, but this is for the Firefox version, and I'm wondering if there's a method for non-JS iMacro code (or, at least, I can't seem to figure out EVAL syntax to write the if check).
https://stackoverflow.com/questions/386 ... ox-imacros

If iMacros is incapable of doing it, then I guess I have no choice but to overwrite the files, which is still technically okay for me, except that iMacros is deleting files from my local directory sometimes. With my existing code, when I downloaded a file, I would do it the first time, get the file successfully, but on the second download (same file), it would sometimes delete the existing file from my directory, and return Error -1415.

I could paste my whole code but really the only relevant line is probably the ONDOWNLOAD line:

Code: Select all

ONDOWNLOAD FOLDER=C:\Users\hob\Desktop\testDir FILE={{acc}}DUE{{date}} WAIT=YES
It's kind of random when it deletes a file, sometimes it will just overwrite without any errors but sometimes the error will happen and stop the script.
Here is the exact copy of the error in my client:

Code: Select all

Error -1415: Cannot find downloaded file 'C:\Users\hob\Desktop\testDir\2241387642DUEJun 26 2017.pdf'. Line 21: ONDOWNLOAD FOLDER=C:\Users\hob\Desktop\testDir FILE={{acc}}DUE{{date}} WAIT=YES
So basically:
1.) Is there a way to check for a file in a local directory, and provide action accordingly based on true/false?
2.) Error -1415 does not exist in iMacro error database, but this isn't a problem if I can figure out the check before downloading at all
3.) What is this .bak file also being generated, is there a way to not download this?
Woaw...!, Compliments for the Quality of your Post/Thread, this should be the "Standard" but unfortunately doesn't occur very often especially with new Users, oops...! :oops: :D
=> Hum, wondering where you got that "FCI" from...!? :wink:

OK...!!, thinking..., thinking..., but yep, my first Idea was indeed to use/misuse '!FOLDER_DATASOURCE' Command like you found out from this SOF Thread, well done...!, I posted the Method btw more than 1 year before @Shugar, ah-ah...!, in this Thread...
But yep, like I said, you can only run a Check on the ReturnCode for the '.iim' Macro (played from 'iimPlay()') and you cannot access this RetCode from the '.iim' Macro itself obviously, because it is still running, ah-ah...!
=> You would indeed need to run your '.iim' Macro from a '.js' Script on FF or using the Scripting Interface, with some '.VBS' or 'C++' or 'C#' or whatever Programming Language you fill confident to use with iMacros...

But OK, some other Method I can think of, in "pure" '.iim' and that therefore would work for iMB (or any other Browser), would be to actually start your Macro (and iMB as well if it's not already running) from a '.BAT' File with an "extra" DOS Command in the '.BAT' before launching iMB + your Macro that would create a 'DIR' Output of your Directory to a '.TXT' File that your Macro could use as a (Temp) DataSource to check if a specific File already exists in the 'DIR' Results...
I demonstrated the Method maybe 2 or 3 months ago, let me find the Thread back...
=> Yep, found it, from 3 months ago indeed... Hum, very-very similar Thread like yours actually, and the User was on iMB v11.5 + Win7 as well, that's why I came up with this Method, I guess... :oops: :
- Choosing uploaded file by date
I gave the whole Idea/Method in my 2nd Post in that Thread, but read the complete Thread and it shouldn't be very difficult to adapt for your own Needs, I would think... :!:

Well, good luck, and I'll be happy to help you a bit further if you get stuck in the 'Process", but my "Impression" is that you are very "capable", ah-ah...! :wink:
(Will be nice btw, and useful for other Users searching the Forum, if you can share your Final Script...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Error -1415 and How to check existence of local files

Post by chivracq » Fri Jun 23, 2017 12:50 am

miscthings wrote:2.) Error -1415 does not exist in iMacro error database, but this isn't a problem if I can figure out the check before downloading at all

Code: Select all

Error -1415: Cannot find downloaded file 'C:\Users\hob\Desktop\testDir\2241387642DUEJun 26 2017.pdf'. Line 21: ONDOWNLOAD FOLDER=C:\Users\hob\Desktop\testDir FILE={{acc}}DUE{{date}} WAIT=YES
3.) What is this .bak file also being generated, is there a way to not download this?
Oh ja, sorry, I only answered your Qt_1, I forgot about the 2 other ones... :oops:

Hum, you're right about Qt_2 and the '-1415' RuntimeError not being listed in the List of RetCodes:
-1410 No Download Detected: Macro contains ONDOWNLOAD, but no download dialog was detected.
-1420 Checksum or Size Not Verified: Checksum or Size of downloaded file does not match specified.
But OK, '-1410' and '-1420' are both related to the 'ONDOWNLOAD' Command, the iMacros Developer sounds pretty clever to me and obviously has a very logical Mind, so I guess '-1415' is as well related to 'ONDOWNLOAD', ah-ah...! 8)

I don't do any Downloads in my own Macros, but I've already seen this RuntimeError actually, I think for this Thread probably in some moment of "intense boredom or pity" (not sure actually...) :oops: I had started to write a Script for, a few weeks ago, hum, never finished it...!, I guess I got a bit busy at some point and didn't find the "Energy" to go digging into it again, and the User didn't try anything by themselves and didn't follow up anymore...
My "Suspicion" is that "your" Error occurs because your Download is at the End of your Macro and the Macro finishes before the Download Popup was fired by the Site/Browser and iMacros had the time to catch it... Try adding some 'WAIT' Statement after it, or some "fake" 'TAG' with a longer '!TIMEOUT_STEP' on some HTML Element on the Page...

And I don't know anything about your Qt_3 and this '.BAK' File, maybe a Temp/Part Download File until the Download has completed...?
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
miscthings
Posts: 4
Joined: Thu Jun 22, 2017 6:56 pm

Re: Error -1415 and How to check existence of local files

Post by miscthings » Fri Jun 23, 2017 4:30 pm

Ahah, I was wondering if I would get a reply from the infamous chivracq! Thanks for all your advice, I will read through the threads and try tinkering with my code a bit more. I'll try to post my solution if I can figure it out for myself!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Error -1415 and How to check existence of local files

Post by chivracq » Fri Jun 23, 2017 7:14 pm

miscthings wrote:Ahah, I was wondering if I would get a reply from the infamous chivracq! Thanks for all your advice, I will read through the threads and try tinkering with my code a bit more. I'll try to post my solution if I can figure it out for myself!
Me, infamous...!?, arrgghhh...!! :shock: I'm only an "unscrupulous bad-ass" for People who don't use the Forum "a bit correctly" I think, I'm a nice Person otherwise, ah-ah...! 8)

But good luck with your "Tinkering" and dare to shout if you get stuck... :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
miscthings
Posts: 4
Joined: Thu Jun 22, 2017 6:56 pm

Re: Error -1415 and How to check existence of local files

Post by miscthings » Mon Jun 26, 2017 5:31 pm

So I read into http://forum.imacros.net/viewtopic.php? ... put#p73319 and from what I understand, I generate a .txt of every file that exists, and then I can search by line or column for an existing one. Well in my case I can't search by line index, so I'm searching by comparing any file name within accounts.txt to a variable. I've taken the code from that page and modified it a bit but I'm getting a syntax error, can't seem to figure out what's wrong. Also I don't know why you're supposed to put \ around the variables, is it because they're special characters? Why is one outside the quotes and one inside?

Code: Select all

PROMPT "Type in a file in testDir" !VAR1
'this PROMPT will be replace later with the variable from the page, just manually inputting it for now to simulate it
SET !DATASOURCE C:\Users\hob\Desktop\testDir\accounts.txt
SET File_Name EVAL("var s='{{!COL1}}'; var x,y,z; z=s.substr(36); z;")
SET !VAR3 EVAL("var s=\"{{!VAR1}}\; var d=\"{{File_Name}}\"; if (d==s){TAG POS=1 TYPE=A ATTR=TXT:My<SP>Account;} else {TAG POS=1 TYPE=A ATTR=TXT:Download};")
Error -1100 appears because of line 5. Is the variable syntax wrong? Can I not put tag inputs directly into if/else? Do I need to contain them within variables? I tried switching them out for URLs:

Code: Select all

SET !VAR3 EVAL("var s=\"{{!VAR1}}\; var d=\"{{File_Name}}\"; if (d==s){var x=\"https://www.google.ca\";} else {var x=\"https://www.youtube.com\";} x;")
but I still got the same error so I don't know...

////////////

Also something I didn't ask originally, may be simpler and would be a backup solution, but I'm pretty sure the answer is no, is there a way that when I download a file that already exists, and the dialogue box pops up with "This file already exists. Overwrite? [Yes] [No]" I can select [No] and have the macro continue? I think I remember reading into this and basically concluded that there was no function to do so. I also tried using !ERRORIGNORE but it didn't change anything. I don't want to use FILEDELETE because I just don't want it to redownload the file, but rather just skip it and move on.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Error -1415 and How to check existence of local files

Post by chivracq » Mon Jun 26, 2017 6:19 pm

miscthings wrote:So I read into http://forum.imacros.net/viewtopic.php? ... put#p73319 and from what I understand, I generate a .txt of every file that exists, and then I can search by line or column for an existing one. Well in my case I can't search by line index, so I'm searching by comparing any file name within accounts.txt to a variable. I've taken the code from that page and modified it a bit but I'm getting a syntax error, can't seem to figure out what's wrong. Also I don't know why you're supposed to put \ around the variables, is it because they're special characters? Why is one outside the quotes and one inside?

Code: Select all

PROMPT "Type in a file in testDir" !VAR1
'this PROMPT will be replace later with the variable from the page, just manually inputting it for now to simulate it
SET !DATASOURCE C:\Users\hob\Desktop\testDir\accounts.txt
SET File_Name EVAL("var s='{{!COL1}}'; var x,y,z; z=s.substr(36); z;")
SET !VAR3 EVAL("var s=\"{{!VAR1}}\; var d=\"{{File_Name}}\"; if (d==s){TAG POS=1 TYPE=A ATTR=TXT:My<SP>Account;} else {TAG POS=1 TYPE=A ATTR=TXT:Download};")
Error -1100 appears because of line 5. Is the variable syntax wrong? Can I not put tag inputs directly into if/else? Do I need to contain them within variables? I tried switching them out for URLs:

Code: Select all

SET !VAR3 EVAL("var s=\"{{!VAR1}}\; var d=\"{{File_Name}}\"; if (d==s){var x=\"https://www.google.ca\";} else {var x=\"https://www.youtube.com\";} x;")
but I still got the same error so I don't know...
Yep the Backslashes are 'Escape' Characters to escape the Special Char coming after, and a Double Quote is a Special Char for JavaScript...
If you notice the Syntax I used myself for the 'File_Name', I prefer to use Single Quotes around Vars or inside JavaScript Commands which don't need to be escaped...

Pb with your '!VAR3' is that you have a missing Double Quote after '{{!VAR1}}', you started to escape it, but you forgot the Double Quote both times...

You cannot place a 'TAG' Statement inside 'EVAL()' indeed...
miscthings wrote:Also something I didn't ask originally, may be simpler and would be a backup solution, but I'm pretty sure the answer is no, is there a way that when I download a file that already exists, and the dialogue box pops up with "This file already exists. Overwrite? [Yes] [No]" I can select [No] and have the macro continue? I think I remember reading into this and basically concluded that there was no function to do so. I also tried using !ERRORIGNORE but it didn't change anything. I don't want to use FILEDELETE because I just don't want it to redownload the file, but rather just skip it and move on.
You can try indeed with some 'ONDIALOG' Statement but I don't think indeed it will work...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
miscthings
Posts: 4
Joined: Thu Jun 22, 2017 6:56 pm

Re: Error -1415 and How to check existence of local files

Post by miscthings » Wed Jun 28, 2017 5:03 pm

I feel like I'm right on the verge of figuring out my solution for the data source but maybe I'm missing something very simple haha...
How do I make datasource-line reference any line? In your example from that thread, you use:

Code: Select all

SET !DATASOURCE D:\TEMP\My_Project\DIR_Output.txt
SET !DATASOURCE_LINE 6

SET File_Name EVAL("var s='{{!COL1}}'; var x,y,z; z=s.substr(36); z;")
PROMPT {{!COL1}}<BR>File_Name:<SP>_{{File_Name}}_
But I need to check my variable against every file name (every line) that exist in my .txt


Also since you mentioned that TAG does not work inside EVAL, is there some way that I can have it click certain tags based on EVAL if/else conditions?
One way I can think of is to put the TAG inside a variable, and run the "raw variable", but iMacros does not allow that haha.

Code: Select all

SET !VAR3 EVAL("var s=\"{{!VAR1}}\"; var d=\"{{File_Name}}\"; if (d==s){var x=\"TAG POS=1 TYPE=A ATTR=TXT:Download\";} else {var x=\"TAG POS=1 TYPE=A ATTR=TXT:My<SP>Account\";} x;")
{{!VAR3}}
Then I tried to use:

Code: Select all

TAG {{!VAR3}}
But obviously that didn't work either:

Code: Select all

 Error -1100: Wrong format of TAG {{!VAR3}} command, at line: 14
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Error -1415 and How to check existence of local files

Post by chivracq » Wed Jun 28, 2017 6:18 pm

miscthings wrote:I feel like I'm right on the verge of figuring out my solution for the data source but maybe I'm missing something very simple haha...
How do I make datasource-line reference any line? In your example from that thread, you use:

Code: Select all

SET !DATASOURCE D:\TEMP\My_Project\DIR_Output.txt
SET !DATASOURCE_LINE 6

SET File_Name EVAL("var s='{{!COL1}}'; var x,y,z; z=s.substr(36); z;")
PROMPT {{!COL1}}<BR>File_Name:<SP>_{{File_Name}}_
But I need to check my variable against every file name (every line) that exist in my .txt
Yep, you are coming close(r) indeed, great feeling I guess to "dig in the dirt" yourself, ah-ah...!? But don't worry, I don't intend to let you suffering in eternal Hell, ah-ah...! :wink:

Euuuuh..., yep, for the other Thread, the User always needed the most recent File I think I remember, and I had used some Switch on the 'DIR' Command to get Files already sorted by Date, while I guess in your Case you'll probably prefer to have the Files sorted alphabetically, which is the Default Behaviour anyway I think, check the Documentation for the 'DIR' DOS Command...

=> I had hardcoded '!DATASOURCE_LINE' = "6" in that Thread because the first File from the 'DIR' Listing was always in ROW_6.
In your Case, you'll want to loop or check several Rows, starting from Row_6.

If you know you always have say Max 10 Files in your Directory or at least with common part in their Filenames that you can list them only from the 'DIR' Command, then you can hardcode the '!DATASOURCE_LINE' from "6" till "15", this is doable, but if you have more Files, you may want to open the 'Output.txt' File directly in a 'TAB_2' and "treat" it as a "Standard" Web-Page for the Browser and iMacros which is then able to extract it like any "Standard" HTML Page/Element, except that the whole Content of that '.txt' Page is seen as ONE HTML Element => ONE Extract, which is very quick but you then need to do some Data Manipulation to re-extract your Filenames.
A "Trick" for "easy" Data Manipulation would be to use some "specific" Char at the beginning and end of your Filenames when saving them (a bit like a Separator)...
miscthings wrote:Also since you mentioned that TAG does not work inside EVAL, is there some way that I can have it click certain tags based on EVAL if/else conditions?
One way I can think of is to put the TAG inside a variable, and run the "raw variable", but iMacros does not allow that haha.

Code: Select all

SET !VAR3 EVAL("var s=\"{{!VAR1}}\"; var d=\"{{File_Name}}\"; if (d==s){var x=\"TAG POS=1 TYPE=A ATTR=TXT:Download\";} else {var x=\"TAG POS=1 TYPE=A ATTR=TXT:My<SP>Account\";} x;")
{{!VAR3}}
Then I tried to use:

Code: Select all

TAG {{!VAR3}}
But obviously that didn't work either:

Code: Select all

 Error -1100: Wrong format of TAG {{!VAR3}} command, at line: 14
You are actually very close with:

Code: Select all

TAG {{!VAR3}}
=> You can use your '{{!VAR3}}' with:

Code: Select all

TAG POS={{!VAR3}} TYPE=... etc
... by spitting out a "0"/"1" for '{{!VAR3}}' with your 'EVAL()'...! :idea:
I've explained the Technique I use in the following Thread:
- Workarounds for Conditional Logic in Macro Code
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply