Can conditional check if folder exist?

Questions and answers on how to get the most out of FFAStrans
Post Reply
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Can conditional check if folder exist?

Post 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?
ThomasM
Site Admin
Posts: 231
Joined: Wed Feb 22, 2017 6:36 am

Re: Can conditional check if folder exist?

Post 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
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Can conditional check if folder exist?

Post by emcodem »

The deliver processor would create the missing directory. Are you sure you need an extra check for the existence of the folder?
emcodem, wrapping since 2009 you got the rhyme?
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Re: Can conditional check if folder exist?

Post 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.
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Can conditional check if folder exist?

Post 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 *
emcodem, wrapping since 2009 you got the rhyme?
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Re: Can conditional check if folder exist?

Post by Conniver »

emcodem, yes, that would also work for this workflow. Thanks.
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Re: Can conditional check if folder exist?

Post 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.
ThomasM
Site Admin
Posts: 231
Joined: Wed Feb 22, 2017 6:36 am

Re: Can conditional check if folder exist?

Post 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!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Can conditional check if folder exist?

Post 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....
emcodem, wrapping since 2009 you got the rhyme?
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Re: Can conditional check if folder exist?

Post 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.
Post Reply