Page 1 of 1

Can conditional check if folder exist?

Posted: Mon Jan 23, 2023 7:48 pm
by Conniver
I use a conditional to check if a file exist, but I also need to check if a folder exist first.

When it finds a new file in the watch folder, I want it to check if the folder \Proxy exist in the same folder as the new file.
If the folder exist, a new conditional checks if the file already has a proxy, before encoding
(this part I have working with "$exists("%s_original_path%\Proxy\%s_original_name%.mp4")".

But is there way to do the same for a folder?

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 7:38 am
by ThomasM
Hi Conniver,

you can do so by using a CommandExecutor-Node:

Code: Select all

%comspec% /C "
IF EXIST
"Drive:\FolderInQuestion"
(EXIT /B 0)
ELSE
(EXIT /B 1)
"
Cheers,
Thomas

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 8:37 am
by emcodem
The deliver processor would create the missing directory. Are you sure you need an extra check for the existence of the folder?

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 9:49 am
by Conniver
Thanks Thomas, but for som reason, it always returns 0, even if the folder is there or not.

Code: Select all

%comspec% /C "
IF EXIST
"%s_original_path%\Proxy"
(EXIT /B 0)
ELSE
(EXIT /B 1)
"
I tried switching the first exit to 1 and second to 0 aswell, same result
I also tried to use "E:\FOLDER\Proxy" instead of s_original_path

I did find a solution, (But I'd really like to figure out how to create exit codes, and why the one above does not work)

Code: Select all

%comspec% /C "mkdir "%s_original_path%\Proxy""
Image
(exist proxy FOLDER node, now only contains "mkdir")

I just the mkdir command, if it creates a Folder its a success, and I cans send it to FFmpeg.
If the folder already exist, it cannot make folder and fails, and I can send it to a new conditional.

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 10:10 am
by emcodem
$exists("%s_original_path%\Proxy\*") > 0 would be true if there is a proxy folder and a file is contained... $exists actually counts files in folders when used with *

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 10:30 am
by Conniver
emcodem, yes, that would also work for this workflow. Thanks.

Re: Can conditional check if folder exist?

Posted: Tue Jan 24, 2023 11:49 pm
by Conniver
ThomasM:
I got the if exist to work, not sure why it didn't work the first time.

Emcodem:
$exist had some issues as it created the Proxy folder and started encoding the first file, the next job still saw no files in the folder while the first was encoding and tried to make the folder again, but failed since the folder already existed at this point.

Re: Can conditional check if folder exist?

Posted: Wed Jan 25, 2023 7:19 am
by ThomasM
Conniver wrote: Tue Jan 24, 2023 11:49 pm ThomasM:
I got the if exist to work, not sure why it didn't work the first time.
[...]
Nice! I even wondered, ´cause I took the code from a workflow of mine which is working well.

Have fun using FFAStrans!

Re: Can conditional check if folder exist?

Posted: Wed Jan 25, 2023 8:06 am
by emcodem
Conniver wrote: Tue Jan 24, 2023 11:49 pm $exist had some issues as it created the Proxy folder and started encoding the first file, the next job still saw no files in the folder while the first was encoding and tried to make the folder again, but failed since the folder already existed at this point.
yeah sometimes this "encode to cache then deliver" strategy that ffastrans is built upon makes sense :D
If you go on and do more stuff with ffastrans you might want to follow this general principle as well by working in the %s_job_work% folder generally and setting %s_source% to the latest active source when you generate source files with cmd processor....

Re: Can conditional check if folder exist?

Posted: Thu Jan 26, 2023 10:35 pm
by Conniver
I fixed the problem where it tried to create the same folder twice.
I just added an extra check if the folder exist, before creating the folder.

first Command executor node, to just check if it exist.

Code: Select all

%comspec% /C
"IF EXIST
"%s_original_path%\Proxy\*"
(EXIT /B 0)
ELSE
(EXIT /B 1)"
second node, to create folder, also checks if folder exist before creating.

Code: Select all

%comspec% /C
"IF EXIST
"%s_original_path%\Proxy\*"
(EXIT /B 0)
ELSE
(mkdir "%s_original_path%\Proxy" && EXIT /B 0)"
This haven't failed any of my tests yet.