JaYo
JaYo

Reputation: 57

How to know if file already exists with Firefox iMacros

I'm using iMacros firefox addon to automatize redundant tasks like downloading bills (pdf files) from a website to my local disk. What I want is, if bill has been already downloaded, to not ask for download next time. Is there a way to know if a file already exists locally ? My macros are integrated in a js script. Thanks for your help.

Upvotes: 0

Views: 883

Answers (3)

ePandit
ePandit

Reputation: 3263

You can make use of SET !DATASOURCE command.

var retCode = iimPlayCode("SET !DATASOURCE C:\\my<SP>folder\\my<SP>file.csv");
if (retCode == 1)
{
    alert("WARNING! - File already exists.");
    //action you want to take
}

Replace all backslash ('\') with '\' and spaces with < SP > (without spaces) in the file path.

You can use FILEDELETE command to delete exisiting file if you want.

Note: Return code 1 means file exists. Not equal to 1 does not mean that file does not exis, there are many return codes possible like -910. See documentation for more detail. However in most cases, you just need to handle file exist case.

Upvotes: 0

user8590779
user8590779

Reputation: 5

var ret = iimPlayCode("SET !FOLDER_DATASOURCE D:\\iMacros\\Downloads\\blablabla.pdf");
if (ret == 1) {
    // file exists
} else {
    // file doesn't exist
}

This code no work for me.

Upvotes: 0

Shugar
Shugar

Reputation: 5299

Here is a simple workaround for that:

var ret = iimPlayCode("SET !FOLDER_DATASOURCE D:\\iMacros\\Downloads\\blablabla.pdf");
if (ret == 1) {
    // file exists
} else {
    // file doesn't exist
}

Upvotes: 1

Related Questions