If File Exist Then and Else

I have a problem with a record delete action
I explain the problem better.
An action to delete records has the following instructions:

  • Query to obtain image and pdf values from the product database
  • If File image exist then remove
  • If File pdf exist then remove
  • if Folder gallery exist then remove
  • Query delete images gallery
  • Query delete record

If the record to be deleted has an image and pdf associated, everything works fine, but if the record has null fields for image and PDF, the action stops and is not performed.
In practice it seems that if if File image exist is false perhaps an else / step statement is needed to exit and continue the subsequent statements
But I do not know how I can do it

You do not need anything in the else statement, it will exit just fine.

I typically have a Condition that wraps the If File Exists that only runs if the dynamic variables have values.

I too was convinced of this and I have never had any problems before.
But in this case, perhaps because NodeJS, if an “if File Exist” results false, the delete action stops

Do I have this problem alone?

I also had a problem using If File Exists and I know this will sound strange, but what I did was not have any steps inside the then or the else, instead i just have the If File Exists with an empty Then and an empty Else. After the step I add a condition, and set the expression to the If File Exists and put my steps inside the condition rather, essentially it does the same thing, but does not break as easily.

Thanks Paul
I don’t know if I understand your suggestion correctly.
First I have to create an “if File Exist” with no then step and no else, and then create a Condition where to insert File remove?

An If File Exists step literally returns a true or false response, so you can do this

As you can see I have no steps at all inside the then / else, but rather a condition afterwards checking it that step returned true or false, and then doing whatever inside it.

I actually think there is a bug with the base If File Exists module because I also had endless trouble with it ending the entire script and was forced to do it like this rather. But it worked great afterwards.

What’s the logic behind this Paul?
Why not put the steps inside the then/else of the file exist step?

I originally had the steps inside the then / else but the scripts kept stopping on my conditions inside them, and I could not get it to work correctly, eventually i switched to this idea, only taking the response of the If file exists step in a new condition and then it all started working as expected.
I meant to actually do a bug report on it at the time, but got involved and forgot.

Will try put some steps together to try show what was not working as I had expected.

What do you mean the script stops? Can you explain this more detailed please?

Yes, putting a test together now to see how i can replicate the problem i was having, will send some screenshots after

Teodor
with the setting of a delete action (like the one in the previous screenshot) I have a problem
If in the record there are fields cover (1 ° if file exits) and pdf (2 ° if file exits) the action completes all the instructions perfectly
But if one or both of the fields are empty, the action is blocked and does not end

Also, of little consequence, if you choose “If folder exist” the name default is file and not folder

Marzio, unfortunately i understood nothing from both of your posts. Hope Paul can explain this in a way it’s clear.

1 Like

First post to simplify
If File Exist record field / then file remove
Result
then - if the record field exist is OK
but if the record field is empty the action stop

action_delete

The second post is just a small report
Choosing if Folder Exist the default name should be foldeExist

I think this image is about the best summary of the issue in my mind

To explain, You can see the silly database table i created for the test, and its one and only record, which has NULL returned for the jpg file.

The result in my mind on the little browser window in the image should be
elsestep and if File Exists = false.

Its like the If File Exists, is saying the file of NULL does exist because the path is semi specified.

If the database holds the entire path, then it works, if the query.tt_jpg is changed to query.tt_jpg.default('mydummyimage.jpg') which does not exist, it works too.

Its like it needs a second check to make sure it is doing an if file exists and not also an if folder exists.

So the issue is that you pass an empty value for the file name, but the if file exists step falsely returns that a file (with such a name?!) exists in the location?

Yes, I think thats the main issue, and I suppose a secondary issue is if you pass the entire path from the database only, and the filepath in the If File Exists has no literal string and only gets the dynamic data then the whole script errors like this

Obviously its pretty silly to hand this poor module NULL values, but with some data structures it does happen.